34,590
社区成员
发帖
与我相关
我的任务
分享
select cid as 专业,
总人数 = count(*),
男人 = sum( case when sex = 'm' then 1 else 0 end),
女人 = sum(case when sex = 'w' then 1 else 0 end),
人妖 = sum(case when sex='u' then 1 else 0 end)
from student
group by cid
create table student
(pid int,
pname nvarchar(20),
sex char(2),
birthday datetime,
cid int
)
insert into student
select 1,'a','w',getdate(),1
union all
select 2,'b','w',getdate(),2
union all
select 3,'c','m',getdate(),3
union all
select 4,'d','u',getdate(),2
union all
select 4,'e','u',getdate(),2
union all
select 4,'f','m',getdate(),2
union all
select 4,'g','m',getdate(),2
select * from student
select cid as 专业,
总人数 = count(*),
男人 = sum( case when sex = 'm' then 1 else 0 end),
女人 = sum(case when sex = 'w' then 1 else 0 end)
from student
group by cid