Microsoft
Software
Hardware
Network
Question : How to count based on a condition in MySQL
How do I count conditionally in MySQL?
SELECT CITY, COUNT(ID) AS TOTALREGISTERED FROM REGISTRATIONS GROUP BY CITY ORDER BY CITY;
Gives me:
New York 16
Cincinatti 14
Miami 11
SELECT CITY, COUNT(ID) AS TOTALATTENDED FROM REGISTRATIONS WHERE ATTENDED='Y' GROUP BY CITY ORDER BY CITY;
Gives me:
New York 8
Cincinatti 6
Miami 3
How can I get:
New York 16 8
Cincinatti 14 6
Miami 11 3
Answer : How to count based on a condition in MySQL
Try this...
SELECT CITY, COUNT(ID) AS TOTALREGISTERED, SUM(CASE WHEN ATTENDED='Y' THEN 1 ELSE 0 END) as TOTALATTENDED FROM REGISTRATIONS GROUP BY CITY ORDER BY CITY
Random Solutions
VPN disconnects over 2 way satellite
Plug n Play/USB/Registry Nigtmare - I Need to regularly delete keys in order to "detect" my MP3 Player!
Older Flash document potential issues
How to change Hotsname and ipaddress of Oracle Databse server
Restricted Groups Best Practice
Progress Bar Bound to Timer
CX600 FLARE 2.05.600.5.007 - upgrade procedure to 2.19?
Windows Server 2008 NLB Issue
quick question
VB.Net exe, icon and shortcut