Last active
December 21, 2015 07:49
-
-
Save swrobel/6274229 to your computer and use it in GitHub Desktop.
Number of orders by product in Spree 2.0+
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
SELECT p.id, | |
sum(quantity) AS num_sold | |
FROM spree_orders o | |
JOIN spree_line_items li ON o.ID = li.order_id | |
JOIN spree_variants v ON li.variant_id = v.id | |
JOIN spree_stock_items i ON v.id = i.variant_id | |
JOIN spree_products p ON v.product_id = p.id | |
WHERE o.state = 'complete' | |
GROUP BY p.id |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment