select 专业,count(*) as 总人数, sum(case 性别 when '男' then 1 else 0 end) as 男生数 , sum(case 性别 when '女' then 1 else 0 end) as 女生数, sum(case rtrim(convert(varchar(20),寄宿))+rtrim(convert(varchar(20),性别)) when '是男' then 1 else 0 end) as 男寄宿生, sum(case rtrim(convert(varchar(20),寄宿))+rtrim(convert(varchar(20),性别)) when '是女' then 1 else 0 end) as 女寄宿生 from student group by 专业 自己回来解答一下