0
林尋找一個SQL查詢獲得直接的我們最暢銷的產品的列表(按數量或按金額排序 - doesn't真正的問題)。這似乎是比我想象的更困難......Magento的:如何查詢(SQL)最暢銷的產品?
搜索與谷歌只找到了PHP模塊等解決方案 - 但我想SQL。
我從不同的站點拿起一個小的查詢和修改了一點:
SELECT
SUM(order_items.qty_ordered) AS ordered_qty, order_items.name AS order_items_name, order_items.product_id AS entity_id,
e.entity_type_id, e.attribute_set_id, e.type_id, e.sku, e.has_options, e.required_options, e.created_at,
e.updated_at FROM sales_flat_order_item AS order_items
INNER JOIN sales_flat_order AS `order` ON `order`.entity_id = order_items.order_id AND `order`.state <> 'canceled'
LEFT JOIN catalog_product_entity AS e
ON
-- (e.type_id NOT IN ('grouped', 'configurable', 'bundle'))
-- AND
e.entity_id = order_items.product_id AND e.entity_type_id = 4
--AND state = "complete"
WHERE (parent_item_id IS NULL)
GROUP BY order_items.product_id
HAVING (SUM(order_items.qty_ordered) > 0)
ORDER BY ORDERED_QTY DESC
它或多或少似乎給一個合理的輸出 - 但這一數字從管理開始屏幕有所不同(只顯示前5名)。
有沒有人做過不便。類似於已經?