可用union all来实现。
如test表中数据如下:
现要将id为3的一条按列显示,可用如下语句:
select to_char(id) str from test where id=3union all
select name from test where id=3
查询结果:
创建表插入数据:
create table test(id int,
field int)
insert into test values (1,101)
insert into test values (1,102)
insert into test values (1,103)
insert into test values (2,36)
insert into test values (2,37)
insert into test values (2,38)
insert into test values (2,39)
commit
执行:
select t.id,max(decode(rn, 1, field, null)) field1,
max(decode(rn, 2, field, null)) field2,
max(decode(rn, 3, field, null)) field3,
max(decode(rn, 4, field, null)) field4,
max(decode(rn, 5, field, null)) field5
from (select test.*, row_number() over(partition by id order by field) rn
from test) t
group by t.id
结果:
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)