Created
October 2, 2014 23:27
-
-
Save kalenjordan/a031f843a92435b2bf2e to your computer and use it in GitHub Desktop.
Orders with Category Data
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
# Get the category name attribute id | |
SELECT attribute_id | |
FROM eav_attribute | |
WHERE entity_type_id = 3 | |
AND attribute_code = 'name'; | |
# Get recent orders with category data | |
SELECT o.created_at | |
, o.entity_id | |
, i.sku | |
, i.product_id | |
, cp.category_id | |
, c.value AS category | |
FROM sales_flat_order_item AS i | |
LEFT JOIN sales_flat_order AS o ON o.entity_id = i.order_id | |
LEFT JOIN catalog_category_product AS cp ON cp.product_id = i.product_id | |
LEFT JOIN catalog_category_entity_varchar AS c ON c.entity_id = cp.category_id AND c.attribute_id = 35 | |
WHERE o.created_at > date_sub(now(), INTERVAL 3 MONTH) | |
LIMIT 1000 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment