34,590
社区成员
发帖
与我相关
我的任务
分享
select stuid ,
max(case stage when '一' then '已评' else '未评' end) [阶段一],
max(case stage when '二' then '已评' else '未评' end) [阶段二],
max(case stage when '三' then '已评' else '未评' end) [阶段三],
max(case stage when '四' then '已评' else '未评' end) [阶段四]
from t_msg
group by stuid
if object_id('[t_msg]') is not null drop table [t_msg]
go
create table [t_msg]([stu_ID] varchar(5),[stage] varchar(2))
insert [t_msg]
select 'B0001','一' union all
select 'B0001','二' union all
select 'B0001','三'
select stu_ID,
阶段一=max(case when stage='一' then '已评' else '未评' end),
阶段二=max(case when stage='二' then '已评' else '未评' end),
阶段三=max(case when stage='三' then '已评' else '未评' end),
阶段四=max(case when stage='四' then '已评' else '未评' end)
from t_msg
group by stu_ID
/**
stu_ID 阶段一 阶段二 阶段三 阶段四
------ ---- ---- ---- ----
B0001 已评 已评 已评 未评
(1 行受影响)
**/
select stu_ID,
阶段一=max(case when stage='一' then '已评' else '未评' end),
阶段二=max(case when stage='二' then '已评' else '未评' end),
阶段三=max(case when stage='三' then '已评' else '未评' end),
阶段四=max(case when stage='四' then '已评' else '未评' end),
from t_msg
group by stu_ID