我想显示销售项目的报告。
产品表
id,name,information,stock,MRP
销售表
id,quantity,sales_price,product_id,sold_quantity.
现在我想要显示所有数量总和的sold_quantity的所有细节。
低于查询运行但是单独运行。我想在一次显示两者,如
SELECT product_id,sum(quantity) as quantity FROM sales GROUP BY product_id;
select product.name,product.information,sales.cost_price,sales.quantity from sales inner join product on sales.product_id=product.id;
答案 0 :(得分:0)
您可以使用子查询来执行此操作,尝试此操作;)
select product.name, product.information, sales.cost_price, sales.quantity, t.quantity as sold_quantity
from sales
inner join product on sales.product_id=product.id
left join (
select product_id, sum(quantity) as quantity
from sales
group by product_id
) t on t.product_id = product.id