我需要在表格中记录每种产品的总和(数量和金额)" account_invoice_line"
SELECT seller.name
ipartner.name AS invoice
brand.name AS brand, pt.name AS product,
SUM(ail.quantity) AS quantity, SUM(ail.price_subtotal) as amount
FROM account_invoice_line ail
LEFT JOIN account_invoice i ON ail.invoice_id = i.id
LEFT JOIN res_partner AS ipartner on ipartner.id = i.partner_id
LEFT JOIN res_users u ON u.id = i.user_id
LEFT JOIN res_partner AS seller ON seller.id = u.partner_id
LEFT JOIN product_product pp ON pp.id = ail.product_id
LEFT JOIN product_template pt ON pt.id = pp.product_tmpl_id
LEFT JOIN brand ON brand.id = pp.brand_id
GROUP BY seller.name, invoice, brand, pt.name
ORDER BY seller.name, invoice, brand, pc.name, pt.name
不幸的是,我得到了这个结果之王:
-
卖方,发票,品牌,产品,数量,金额
...
卖方1,客户1,品牌1,产品1,5,4.70
卖方1,客户1,品牌1,产品1,10,9.30
...
我期待这个(相同产品的总数量和数量):
卖方1,客户1,品牌1,产品1,15,14.0
答案 0 :(得分:0)
您确定所有表格都需要左连接吗? 使用account_invoice_line然后添加LEFT JOIN,可能会使其中一个字段在其他表上为NULL,这可能是您看到2个记录而不是一个记录的原因(假设其中一个记录中的伙伴ID为NULL)。 / p>
答案 1 :(得分:0)
如果你只是按一个列名分组(例如:品牌),你还能得到相同的结果吗?