Last active
January 1, 2016 20:59
-
-
Save kalenjordan/8200459 to your computer and use it in GitHub Desktop.
Magento Repurchase Rate Note: This assumes you don't use guest checkout - if you do, you could probably group by customer_email and get relatively accurate results.
This file contains 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
# The number of customers who haveve only purchased once from December 2012 to December 2013 | |
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' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment