Skip to content

Instantly share code, notes, and snippets.

@webdawe
Created September 28, 2016 03:01
Show Gist options
  • Save webdawe/f32b22624456634b95cac999583c6a1c to your computer and use it in GitHub Desktop.
Save webdawe/f32b22624456634b95cac999583c6a1c to your computer and use it in GitHub Desktop.
Category Product Sales Report
#category_products_sales_report
SET @categoryEntityTypeId := (SELECT entity_type_id FROM eav_entity_type WHERE entity_type_code = 'catalog_category');
SET @nameAttributeId := (select attribute_id FROM eav_attribute where attribute_code = 'name' and entity_type_id = @categoryEntityTypeId);
SET @categoryId = 1;
select w.name as website_name, oi.name, SUM(oi.base_row_invoiced) as total,SUM(qty_invoiced) FROM catalog_category_product cp
INNER JOIN sales_flat_order_item oi ON oi.product_id = cp.product_id
INNER JOIN core_store s ON s.store_id = oi.store_id
INNER JOIN core_website w ON w.website_id = s.website_id
WHERE cp.category_id = @categoryId
AND oi.created_at > DATE_SUB(NOW(), INTERVAL 12 MONTH)
group by oi.product_id,oi.store_id;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment