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
Outlook Web App Options
Remote Desktop Client help
Having a problem json encoding a string with quotes
Strip Attachments From Exchange 2007
external drive shows up as uninitialized
Outlook 2003 Send mail issue
How to send email from Outlook when away from the Exchange Server?
How to read the data from MQRFH2 messages using MQ connector stage
Accessing an FTP server internally that is on a different subnet.
How do create a Windows batch script to start a service and set to automatic