Skip to content

Instantly share code, notes, and snippets.

@webdawe
Last active December 29, 2022 14:15
Show Gist options
  • Save webdawe/f8dbaa790ecb91b318f2517a40c2a7b0 to your computer and use it in GitHub Desktop.
Save webdawe/f8dbaa790ecb91b318f2517a40c2a7b0 to your computer and use it in GitHub Desktop.
Query for retrieving country wise sales report from Magento Database
SET @fromDate = DATE_SUB(NOW(), INTERVAL 1 YEAR);
SELECT country_id, count(*) as total_orders,SUM(s.grand_total)
FROM `sales_flat_order_address` a
INNER JOIN sales_flat_order s ON s.entity_id = a.parent_id
WHERE s.created_at >= @fromDate
AND a.address_type = 'shipping'
GROUP BY country_id
ORDER BY total_orders DESC
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment