Last active
October 17, 2016 23:11
-
-
Save webdawe/5807cd693b48f7196c279f4ece8be760 to your computer and use it in GitHub Desktop.
Query for retrieving statewise sales summary from Magento Database
This file contains 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
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