Created
January 9, 2014 16:00
-
-
Save tegansnyder/8336537 to your computer and use it in GitHub Desktop.
Finding the category that has the most sales in Magento
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 cat_id, SUM(row_total) as total_sales_by_cat, cv.value FROM ( | |
SELECT c2.entity_id as cat_id, si.row_total | |
FROM catalog_category_product c1 | |
INNER JOIN catalog_category_entity_varchar c2 ON (c1.category_id = c2.entity_id) | |
INNER JOIN catalog_product_entity c3 ON (c1.product_id = c3.entity_id) | |
INNER JOIN sales_flat_order_item si ON (si.product_id = c3.entity_id) | |
WHERE c2.attribute_id = (SELECT attribute_id FROM eav_attribute WHERE attribute_code = 'name' AND entity_type_id = 3) | |
ORDER BY si.created_at DESC | |
) main | |
INNER JOIN catalog_category_entity_varchar cv ON (cv.entity_id = cat_id) | |
GROUP BY cat_id | |
ORDER BY total_sales_by_cat DESC |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment