在prestashop中获取所有已售出的产品组合数量

时间:2018-03-06 10:20:44

标签: mysql prestashop

我试图在Prestashop SQL Manager中进行查询,这将返回所有已售出的组合数量(例如:Dress XL - 200)。我最终得到了

SELECT P.reference as SKU, 
PL.`name` as Product_Name, 
COUNT(OD.id_order) as ordered_qty FROM ps_product P
LEFT JOIN ps_product_lang PL ON P.id_product = PL.id_product
LEFT JOIN ps_order_detail OD ON P.id_product = OD.product_id
LEFT JOIN ps_orders O ON O.id_order = OD.id_order
WHERE O.valid = 1 AND O.`date_add`  >  '2017-03-01 00:00:00'
GROUP BY P.reference, PL.`name`, OD.id_order
ORDER BY ordered_qty DESC

但它显示了一些奇怪的数据(产品名称位于不正确的位置等),最重要的是 - 不知道如何显示组合。 任何帮助,将不胜感激。

1 个答案:

答案 0 :(得分:1)

检查

SELECT 
OD.`product_id`, 
OD.`product_attribute_id`,
OD.`product_name`,
sum(OD.`product_quantity`) as qty
FROM ps_order_detail OD
WHERE O.valid = 1 AND O.`date_add` > '2017-03-01 00:00:00'
LEFT JOIN ps_orders O ON O.id_order = OD.id_order
GROUP BY OD.`product_id`, OD.`product_attribute_id`
ORDER BY qty DESC