Last active
January 1, 2016 20:59
-
-
Save kalenjordan/8200459 to your computer and use it in GitHub Desktop.
Revisions
-
kalenjordan revised this gist
Dec 31, 2013 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,4 @@ # The number of customers who haveve only purchased once from December 2012 to December 2013 SELECT customers_in_segment FROM -
kalenjordan revised this gist
Dec 31, 2013 . 1 changed file with 2 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,5 @@ # Test SELECT customers_in_segment FROM ( -
kalenjordan revised this gist
Dec 31, 2013 . 1 changed file with 4 additions and 5 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,3 @@ SELECT customers_in_segment FROM ( @@ -21,9 +20,9 @@ UNION SELECT count(*) FROM ( SELECT customer_id, min(created_at) AS first_order_at, count(*) AS order_count FROM sales_flat_order WHERE created_at < '2013-12-31' GROUP BY customer_id ) AS summary WHERE first_order_at BETWEEN '2012-12-01' AND '2012-12-31' -
kalenjordan revised this gist
Dec 31, 2013 . 1 changed file with 0 additions and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,4 @@ SELECT customers_in_segment FROM ( -
kalenjordan created this gist
Dec 31, 2013 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,30 @@ # The number of customers who've only made one purchase SELECT customers_in_segment FROM ( SELECT count(*) AS customers_in_segment, order_count FROM ( SELECT customer_id, min(created_at) AS first_order_at, count(*) AS order_count FROM sales_flat_order WHERE created_at < '2013-12-31' GROUP BY customer_id ) AS summary WHERE first_order_at BETWEEN '2012-12-01' AND '2012-12-31' GROUP BY order_count ) AS summary2 WHERE order_count = 1 UNION # The total number of new customers in December 2012 SELECT count(*) FROM ( SELECT customer_id, min(created_at) AS first_order_at, count(*) AS order_count FROM sales_flat_order WHERE created_at < '2013-12-31' GROUP BY customer_id ) AS summary WHERE first_order_at BETWEEN '2012-12-01' AND '2012-12-31'