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
File Find/Replace(or Amend) string/update file
Send two files in email as attachment in unix shell scripting using ksh
how can i pay electricity bill online using hdfc netbanking ??
SQL Server 2005 Database Backup
Settings.xml
checking what is TRANSACTION ISOLATION LEVEL right now
OCS 2007 R2 - Failure [0xC3FC200D] One or more errors were detected
Perl, Using Text::CSV_XS / Count number of references
DNS Event ID's 4010 & 4013
server raid6