Abdessamad Abdessamad - 1 year ago 92
SQL Question

MySQL: Sum () and Count in one query?

I'm looking for help using sum() and count () in my SQL query:

select s1_s2,count(s1_s2) as RES
from city_user
where s1_s2 in (select s1_s2 from city_user )
group by s1_s2

result: Image Query Result

I want to make sum () for RES column

Is that possible?

Answer Source

thanks for your answers

this what I wanted:

look this pic : result

this query works fine for me:

select s1_s2,
count(s1_s2) as res,
(select sum(res) as sum from (
  select s1_s2, count(s1_s2) as res from city_user group by s1_s2) city_user) as Sum_RES from city_user  group by s1_s2
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download