表: sal_a
字段: A
B
C
D
.
.
.
X
Y
Z
查询结果要这个样的: 字段:| A | B | C | D | E |
值:| 8.9 | 6.4 | 3.2 | 0 | 12 |
… | …
字段:| X | Y | Z
值:| 9 | 8.7 | 6.5
字段: A
B
C
D
.
.
.
X
Y
Z
查询结果要这个样的: 字段:| A | B | C | D | E |
值:| 8.9 | 6.4 | 3.2 | 0 | 12 |
… | …
字段:| X | Y | Z
值:| 9 | 8.7 | 6.5
值:| 8.9 | 6.4 | 3.2 | 0 | 12 |
… | …
字段:| X | Y | Z
值:| 9 | 8.7 | 6.5 select A,B,C,D,E
UNION ALL
SELECT .......
值:| 8.9 | 6.4 | 3.2 | 0 | 12 |
… | …
字段:| X | Y | Z
值:| 9 | 8.7 | 6.5
...........
字段:| A | B | C | D | E |
值:| 8.9 | 6.4 | 3.2 | 0 | 12 |
… | …
字段:| X | Y | Z
值:| 9 | 8.7 | 6.5 其中字母为字段名称,数字为字段的值
select 'A'c1,'B'c2,'C'c3,'D'c4,'E'c5 from dual
union all select to_char(a),to_char(b),to_char(c),to_char(d),to_char(e) from sal_a
union all select 'F','G','H','I','J' from dual
union all select to_char(f),to_char(g),to_char(h),to_char(i),to_char(j) from sal_a
union all ....这样呢
with sal_a as(
select 1 a,2 b,3 c,4 d,5 e,6 f,7 g,8 h,9 i,10 j,11 k,12 l,13 m,14 n from dual
union all select 1.1,2.2,3.3,4.4,5.5,6.6,7.7,8.8,9.9,0.0,11.11,12.12,13.13,14.14 from dual)
,t as (select a.*,row_number()over(order by rownum)rn from sal_a a)select a,b,c,d,e,rn+0.1 flag
from t
union all select f,g,h,i,j,rn+0.2 from t
union all select k,l,m,n,null,rn+0.3 from t
union all select null,null,null,null,null,rn+0.4 from t
order by 6;A B C D E FLAG
1 2 3 4 5 1.1
6 7 8 9 10 1.2
11 12 13 14 1.3
1.4
1.1 2.2 3.3 4.4 5.5 2.1
6.6 7.7 8.8 9.9 0 2.2
11.11 12.12 13.13 14.14 2.3
2.4
一条记录要显示成这样: 字段:| A | B | C | D | E |
值:| 8.9 | 6.4 | 3.2 | 0 | 12 |
… | …
字段:| X | Y | Z
值:| 9 | 8.7 | 6.5
...........
字段:| A | B | C | D | E |
值:| 8.9 | 6.4 | 3.2 | 0 | 12 |
… | …
字段:| X | Y | Z
值:| 9 | 8.7 | 6.5 其中字母为字段名称,数字为字段的值
如果是这样的话可以试试
select 'A'c1,'B'c2,'C'c3,'D'c4,'E'c5 from dual
union all select to_char(a),to_char(b),to_char(c),to_char(d),to_char(e) from sal_a
union all select 'F','G','H','I','J' from dual
union all select to_char(f),to_char(g),to_char(h),to_char(i),to_char(j) from sal_a
union all .... ----------------------------------
先谢过啦...单挑记录结果正确,但是记录多了效果就变啦!
可不可按照某个字段进行分组呢?