Last active
September 15, 2015 20:13
-
-
Save mrw/a71d25c05d6d156e8bb2 to your computer and use it in GitHub Desktop.
CartThrob sales by product within a date range
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
SELECT | |
products.entry_id, | |
products.title, | |
order_items.price, | |
SUM(order_items.quantity) AS total_sold, | |
SUM(order_items.quantity) * order_items.price AS total_price | |
FROM | |
exp_cartthrob_order_items AS order_items | |
INNER JOIN exp_channel_titles AS products | |
USING(entry_id) | |
INNER JOIN exp_channel_titles AS orders | |
ON (orders.entry_id = order_items.order_id) | |
WHERE | |
orders.entry_date < UNIX_TIMESTAMP('2015-09-14') | |
AND orders.entry_date > UNIX_TIMESTAMP('2015-08-14') | |
AND orders.status = 'Open' | |
GROUP BY | |
order_items.entry_id, | |
products.title | |
ORDER BY | |
total_price DESC |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment