MYSQL查询 - 多个喜欢

时间:2014-06-20 18:37:33

标签: mysql

坚持这个查询。显然我下面的内容是错误的,但希望它能成为我想要做的事情。

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;

我确定我离开这里。

由于

1 个答案:

答案 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