Created
June 28, 2017 20:42
-
-
Save leewillis77/c07c22ec791307d2c25b77439495805e to your computer and use it in GitHub Desktop.
Subselect instead of view proof-of-concept
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/includes/class-campaigns-db.php b/includes/class-campaigns-db.php | |
index bc572401..ee2e9892 100644 | |
--- a/includes/class-campaigns-db.php | |
+++ b/includes/class-campaigns-db.php | |
@@ -27,10 +27,21 @@ class Affiliate_WP_Campaigns_DB extends Affiliate_WP_DB { | |
if( defined( 'AFFILIATE_WP_NETWORK_WIDE' ) && AFFILIATE_WP_NETWORK_WIDE ) { | |
// Allows a single visits table for the whole network | |
- $this->table_name = 'affiliate_wp_campaigns'; | |
+ $visits_db = 'affiliate_wp_visits'; | |
} else { | |
- $this->table_name = $wpdb->prefix . 'affiliate_wp_campaigns'; | |
+ $visits_db = $wpdb->prefix . 'affiliate_wp_visits'; | |
} | |
+ | |
+ $this->table_name = '( | |
+ SELECT affiliate_id, | |
+ campaign, | |
+ COUNT(url) as visits, | |
+ COUNT(DISTINCT url) as unique_visits, | |
+ SUM(IF(referral_id<>0,1,0)) as referrals, | |
+ ROUND((SUM(IF(referral_id<>0,1,0))/COUNT(url)) * 100, 2) as conversion_rate | |
+ FROM ' . $visits_db . ' GROUP BY affiliate_id, campaign | |
+ ) AS summary_stats'; | |
+ | |
$this->primary_key = 'affiliate_id'; | |
$this->version = '1.0'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment