SQLize Online / PHPize Online  /  SQLtest Online

A A A
Share      Blog   Popular
Copy Format Clear
create table ListTable ( id int, userID int ); create table PeopleTable ( id int, gender char ); insert into ListTable values (1, 1); insert into PeopleTable values (1, 'M'); SELECT * FROM ListTable AS list LEFT JOIN PeopleTable AS people ON (list.userID = people.id) WHERE people.gender = 'M'; 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 FROM ListTable AS list LEFT JOIN PeopleTable AS people ON (list.userID = people.id) -- WHERE people.gender = 'М'
Stuck with a problem? Got Error? Ask ChatGPT!
Copy Clear