Permalink
Cannot retrieve contributors at this time
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
7 lines (7 sloc)
667 Bytes
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
SELECT sfoi.sku AS SKU, sum(qty_ordered) AS Qty , name AS Description | |
FROM `sales_flat_order_item` AS sfoi | |
JOIN `catalog_product_entity` AS cpe ON cpe.entity_id = sfoi.product_id | |
GROUP BY product_id | |
ORDER BY sum(qty_ordered) DESC | |
LIMIT 5 | |
/*However this query does not address the situation when we have more than five most popular product with the same number of units sold. If we have two products that were sold equal number of times, ‘Top Product Number Five’ and ‘Top Product Number 6′, MySQL will return either the ‘Top Product Number Five’ or the ‘Top Product Number 6′ randomly for the fifth most popular product each time we run the query.*/ |