我有一张桌子
user_name id status calls
===========================================
apple 21 cars 67
apple 21 bikes 85
apple 21 skates 6
apple 21 pajs 56
orange 34 bikes 9
orange 34 disks 3
orange 34 cars 21
orange 34 pajs 76
我想将status's
的所有调用添加为仅限汽车,自行车和冰鞋以及每个user_name。我已经遇到了SUM
但经过几个小时的深夜,我认真地尝试了这个需要更多的东西。有人能指出我正确的方向吗?
答案 0 :(得分:4)
select user_name, status, sum(calls) as calls
from table
where status in ('cars', 'bikes', 'skates')
group by user_name, status