我想從我的查詢結果如下:MySQL的子查詢
id_product_attribute | id_product | reference | name | total
12 | 1 | 234235 | product_name | 2
14 | 2 | 235435 | product_name | 7
16 | 3 | 235325 | product_name | 4
等
但是當我使用此查詢:
select pa.id_product_attribute, p.id_product, pa.reference, cl.name, sum(od.product_quantity) as total
from ps_product_attribute pa
left join ps_order_detail od on od.product_attribute_id = pa.id_product_attribute
left join ps_product p on pa.id_product = p.id_product
left join ps_category_product cp on cp.id_product = p.id_product
left join ps_category_lang cl on cp.id_category = cl.id_category
where cp.id_category = 141 and cl.id_lang = 6;
它僅給出這個我結果:
id_product_attribute | id_product | reference | name | total
12 | 1 | 234235 | product_name | 13
所以在'total'列顯示了所有的總數,而不是每行的分隔數。
任何人都可以告訴我我在做什麼錯在我的查詢?
做到了這一招,謝謝! –