Hi! Could we please enable some services and cookies to improve your experience and our website?

SQLize | PHPize | SQLtest

Online Sandbox for SQL and PHP: Write, Run, Test, and Share SQL Queries and PHP Code

A A A
Login    Share code      Blog   FAQ
Copy Format Clear
create table ListTable ( id int, userID int ); create table PeopleTable ( id int, gender char ); insert into ListTable values (1, 1), (2, 2), (3, 3); insert into PeopleTable values (1, 'M'), (2, 'F'); SELECT COUNT(DISTINCT CASE WHEN people.gender = 'M' THEN list.id END) AS mens, COUNT(DISTINCT CASE WHEN people.gender = 'F' THEN list.id END) AS womens, COUNT(DISTINCT CASE WHEN people.gender IS NULL THEN list.id END) AS unknown FROM ListTable AS list LEFT JOIN PeopleTable AS people ON (list.userID = people.id) ;

Stuck with a problem? Got Error? Ask AI support!

Copy Clear