我有类似下面的输出。
我希望将其转换为以下内容
ID是TOTAL,HIGH,SENT,WAITING,DATE的计数。我已经考虑了一段时间,却无法获得想要的东西。任何人都可以在ORACLE SQL中提供帮助吗?
提前感谢。
这里是一个选择:
SQL> with test (cdate, total, high, sent, waiting, loc) as
2 (select 1012018, 23, 4, 35, 45, 13456 from dual union all
3 select 1212018, 74, 2, 77, 82, 98765 from dual
4 ),
5 temp as
6 (select 5 rn, loc, cdate as value from test union all
7 select 1 rn, loc, total from test union all
8 select 2 rn, loc, high from test union all
9 select 3 rn, loc, sent from test union all
10 select 4 rn, loc, waiting from test
11 )
12 select rn, value, loc
13 from temp
14 order by loc, rn;
RN VALUE LOC
---------- ---------- ----------
1 23 13456
2 4 13456
3 35 13456
4 45 13456
5 1012018 13456
1 74 98765
2 2 98765
3 77 98765
4 82 98765
5 1212018 98765
10 rows selected.
SQL>