数据源:
效果图:
语句:
-- 此语句是按照eparchy_code分组后进行行转列,如无需分组,则去掉repair_num即可
select eparchy_code,repair_name1,repair_name2,repair_name3 from (
select row_number() over (partition by eparchy_code order by id) as repair_num,
eparchy_code,repair_name from TS_S_SJZXTJ
) a pivot(
max(repair_name) for repair_num in (
'1' as repair_name1,
'2' as repair_name2,
'3' as repair_name3
)
)
-- 语句说明 :
max(repair_name[需要转的列]) for repair_num[编号] in (
'1[当编号=1]' as repair_name1,
'2[当编号=2]' as repair_name2,
'3[当编号=3]' as repair_name3
)