SELECT
SUM ( CASE WHEN id = 1 THEN 1 ELSE 0 END ) AS [id为1的总段哗数],
SUM ( CASE WHEN id = 1 AND SEX = 1 THEN 1 ELSE 0 END ) AS [id为1 sex=1的总知燃燃搭虚数]
FROM
表
求出ID为渣仿1的总和
select count(1) rn
from table_name
where id = 1
求出sex为1的总和,不算晌喊id重如谨纤复的
select count(distinct id) rn
from table_name
where sex = 1
select count(*) 总人弊返数,sum(sex) 男生人数 from 表
呵拦拦呵,有点投简卜胡巧哦