Skip to content

Instantly share code, notes, and snippets.

@kalenjordan
Created October 2, 2014 23:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kalenjordan/a031f843a92435b2bf2e to your computer and use it in GitHub Desktop.
Save kalenjordan/a031f843a92435b2bf2e to your computer and use it in GitHub Desktop.
Orders with Category Data
# 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