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
Usning the wizard control in asp.net
WINDOWS 2003 SP2 MEMBER SERVER TO 2003 R2
XP Compatibility Mode - Intermittant - Drives mapped to Host Machine don't work
Cancel a tween in Flash CS4
Exchange 2007 Connectivity problems
How do I implement a vlan for a hotel.
Internet searches getting redirected to advertising websites
How to run app on local machine and display results in web page
Trying to connect to the server using Microsoft SQL Server Management Studio
Sharepoint Survey: Clicked 'No' to 'Show user names while creating the survey! Is there a way to turn the feature back on to see the names again?