Skip to content

Instantly share code, notes, and snippets.

@webdawe
Last active October 17, 2016 23:11
Show Gist options
  • Save webdawe/5807cd693b48f7196c279f4ece8be760 to your computer and use it in GitHub Desktop.
Save webdawe/5807cd693b48f7196c279f4ece8be760 to your computer and use it in GitHub Desktop.
Query for retrieving statewise sales summary from Magento Database
SET @countryId = 'US';
SET @storeId = 7;
SELECT a.region,SUM(s.grand_total) AS total,COUNT(*) AS no_of_orders FROM sales_flat_order s
INNER JOIN sales_flat_order_address a ON a.entity_id = s.shipping_address_id
WHERE s.created_at >= DATE_SUB(NOW(), INTERVAL 1 YEAR)
AND a.address_type = 'shipping'
AND s.store_id = @storeId
AND a.country_id = @countryId
GROUP BY a.region
ORDER BY total desc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment