mysql - how to write the sql -


i have table like

id      user_id    type 1         1         2 2         1         1 3         3         3 4         3         1 5         6         2  6         6         3  

and want sum of user_id = 1 , user_id =3 , every type sum in user_id = 1 , user_id =3 ,it can 2 sql result is

sum  4  type sum  1    2     2    1  3    1 

the first function needed achieve result count() not sum() function

for first result

select count(*) sum user1 user_id in(1,3) 

for second result need select type , should grouped

 select type, count(*) sum user1 user_id in(1,3)     group type 

fiddle second can check first 1 there taking query

next time post effort. guess naive sql.


Comments