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
5 hour time difference.
HP z200 Workstation Windows 2008 R2 'PCI serial port' driver and 'PCI Simple Communications controller' driver needed
Create subdomain in iis7 w2008 server
OCS 2007 R2 and Cisco call manager
Terminal server 2008 R2 Pinned Taskbar Links
Move applications between networked computers
Windows Update Error on Hyper-V guest on a HP Proliant ML370 G6 (NC375i network card)
Select All Columns Count Column Group By Only One Column?
Windows 7 recently used programs is blank
Reset Root Password on a MAC