gpt4 book ai didi

MYSQL查询-多次点赞

转载 作者:行者123 更新时间:2023-11-29 12:54:08 25 4
gpt4 key购买 nike

卡在这个查询上。显然我下面的内容是错误的,但希望它能让我想要做的事情变得清晰。

SELECT branch, 
SUM(price * quantity) as "Office" FROM orders WHERE account LIKE "0%"
and
SUM(price * quantity) as Personal FROM orders WHERE account LIKE "1%"
GROUP BY branch;

我确信我已经离这里很远了。

谢谢

最佳答案

在每个总和中使用一个case:

select branch,
sum(case when account like '0%' then price * quantity else 0 end) as Office,
sum(case when account like '1%' then price * quantity else 0 end) as Personal
from orders
group by branch

关于MYSQL查询-多次点赞,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24333649/

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