当前位置:首页>正文

Oracle中关于列转行:采用Union连接起来好,还是采用unpivot函数好

2023-06-27 11:08:26 互联网 未知

Oracle中关于列转行:采用Union连接起来好,还是采用unpivot函数好?

建议使用unpivot
不然使用这种方式也可以

111111 Select
id,
Case
WhenTID=1 Thenc1 
WhenTID=2 Thenc2 
WhenTID =3 Thenc3 
WhenTID=4 Thenc4 ElseNullEndasnewCell
From
(--这个是数据源,这里为了方便测试暂时拼接一个作为数据源
Select1 asid, aasc1,basc2 ,casc3,dascUnionAllSelect2 asid, easc1,fasc2 ,gasc3,hascUnionAllSelect3 asid, iasc1,jasc2 ,kasc3,masc) ass LeftJoin
--这个表是拼接起来的,拼几行要看你有几列
(Select1 asTID UnionAllSelect2 UnionAllSelect3 UnionAllSelect4) ast
On0=0