22,209
社区成员
发帖
与我相关
我的任务
分享
--> 测试数据:[test]
if object_id('[test]') is not null drop table [test]
create table [test]([时段] int,[访问量] int,[受理量] int,[放弃量] int)
insert [test]
select 1,1,1,3 union all
select 2,4,5,6 union all
select 3,6,4,5
select '访问量' as 时间,
max(case when [时段]=1 then [访问量] else 0 end) as [1],
max(case when [时段]=2 then [访问量] else 0 end) as [2],
max(case when [时段]=3 then [访问量] else 0 end) as [3]
from test
union all
select '受理量' as 时间,
max(case when [时段]=1 then 受理量 else 0 end) as [1],
max(case when [时段]=2 then 受理量 else 0 end) as [2],
max(case when [时段]=3 then 受理量 else 0 end) as [3]
from test
union all
select '放弃量' as 时间,
max(case when [时段]=1 then 放弃量 else 0 end) as [1],
max(case when [时段]=2 then 放弃量 else 0 end) as [2],
max(case when [时段]=3 then 放弃量 else 0 end) as [3]
from test
/*
时间 1 2 3
访问量 1 4 6
受理量 1 5 4
放弃量 3 6 5
*/
简单易懂