笔记7 case when实现交叉表还有子查询
笔记7 case when实现交叉表还有子查询
1 case when实现交叉表还有子查询 2 USE pratice 3 4 ;with maco as 5 ( 6 select *,row_number() over (partition by [A] order by (select 1)) as id from testpivot 7 ) 8 9 select A , 10 max(case id when '1' then B else null end) A1, 11 max(case id when '2' then B else null end) A2, 12 max(case id when '3' then B else null end) A3 13 from maco group by A 14 15 select *,row_number() over (partition by [A] order by (select 1)) as id from testpivot 16 17 --子查询 18 --select A 19 --FROM ( 20 -- SELECT * FROM testpivot 21 -- )AS [pivottable]