gpt4 book ai didi

mysql Group by X 并显示Total1(同表的Field = 0时)和Total2(Field = 1时)

转载 作者:太空宇宙 更新时间:2023-11-03 11:32:10 25 4
gpt4 key购买 nike

我有这个查询返回图像显示:

SELECT a.idarticle, c.stock, a.libelle as 'Libelle', sum(a.price * o.quantity) as `Total` from command c
inner join store s on c.idstore = s.idstore
inner join operation o on c.idcommand = o.idcommand
inner join article a on o.idarticle = a.idarticle
group by o.idarticle, c.stock

Image

我想要:ID、Libelle、Total1(当 stock = 0 时)、Total2(当 stock = 1 时)

谢谢

最佳答案

我想这就是您要找的:

SELECT a.idarticle, a.libelle as 'Libelle', 
sum(case when stock = 0 then a.price * o.quantity) as `Total1` ,
sum(case when stock = 1 then a.price * o.quantity) as `Total2`
from command c
inner join store s on c.idstore = s.idstore
inner join operation o on c.idcommand = o.idcommand
inner join article a on o.idarticle = a.idarticle
group by a.idarticle, a.libelle

关于mysql Group by X 并显示Total1(同表的Field = 0时)和Total2(Field = 1时),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48936138/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com