Mysql中表student_table(id,name,birth,sex),id字段值可能重复,分别查询男生、女生的不重复id总数,如下SQL正确的是()?
select
sum(distinct case when sex='男' then 1 else null end) as man_ids,
sum(distinct case when sex='女' then 1 else null end) as women_ids
from student_table;
select
count(distinct case when sex='男' then id else null end) as man_ids,
count(distinct case when sex='女' then id else null end) as women_ids
from student_table;
select
count(distinct case when sex='男' then 1 else null end) as man_ids,
count(distinct case when sex='女' then 1 else null end) as women_ids
from student_table;
select
count(case when sex='男' then distinct id else null end) as man_ids,
count(case when sex='女' then distinct id else null end) as women_ids
from student_table;
select
sum(distinct case when sex='男' then 1 else null end) as man_ids,
sum(distinct case when sex='女' then 1 else null end) as women_ids
from student_table;