简体   繁体   English

按行数多个行的数学和

[英]Mathematical SUM of multiple rows by value

I have a table 我有一张桌子

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

I want to add up all the calls for status's that are cars, bikes and skates only and for each user_name. 我想将所有status's调用添加到汽车,自行车和溜冰鞋以及每个user_name。 I have experminted with SUM but after several hours of late night, earnest attempts its pretty clear to me that this is going to require more than that. 我已经体验过SUM但经过几个小时的深夜,我认真地尝试了这个需要更多的东西。 Can anyone point me in the right direction please? 有人能指出我正确的方向吗?

My Table 我的表

select user_name, status, sum(calls) as calls
from table
where status in ('cars', 'bikes', 'skates')
group by user_name, status

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM