tags:

views:

55

answers:

2

hey

in my members table i would like a summary of all different people in "locations" 1 - 7 of how many people are online and offline.

SELECT location, COUNT(*) FROM members GROUP BY location;

that returns:

1 10  
2 5  
3 4  
4 12  
5 6  
6 3  
7 19  

I would like a COUNT for members with a status of 0 (offline) and a status of 1 (online). how do i do this?

+2  A: 

SELECT location, status, COUNT(*) FROM members GROUP BY location, status

dbemerlin
+1 for fastest.
Mark Byers
+4  A: 
SELECT location, status, COUNT(*) FROM members GROUP BY location, status

As one row:

SELECT
    location,
    COUNT(status) - SUM(status) as offline,
    SUM(status) as online
FROM members
GROUP BY location
Mark Byers
this works but it creates two rows for each location, which would make it awkward in my php as i print this data out in a table.
Juddling
@Juddling: See update.
Mark Byers
you're a genius!
Juddling