Mathematical SUM of several lines 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 all the challenges for status's , which are only for cars, bicycles and skates, and for each username. I experimented with SUM , but after several hours of late night, serious attempts made it pretty clear to me that it would require more than that. Can someone point me in the right direction?

My table

+4
source share
1 answer
 select user_name, status, sum(calls) as calls from table where status in ('cars', 'bikes', 'skates') group by user_name, status 
+4
source

Source: https://habr.com/ru/post/1439385/


All Articles