坚持这个查询。显然我下面的内容是错误的,但希望它能成为我想要做的事情。
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;
我确定我离开这里。
由于
答案 0 :(得分:1)
在每笔金额中使用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