oracle列行转换的问题

来源:百度知道 编辑:UC知道 时间:2024/06/07 13:16:42
有一个表
PID INAME CONTENT
-------------------------------- -------------------- --------------------
1 item01 1-1
2 item01 2-1
3 item01 3-1
4 item01 4-1
5 item01 5-1
6 item01 6-1
7 item01 7-1
8 item01 8-1

1 item02 1-2
2 item02 2-2
3 item02 3-2
4 item02 4-2
5 item02 5-2
6

楼上写的对的,我补充一下

select pid,max(item01) item01,max(item02) item02,max(item03) item03 from
(
select pid,
decode(INAME,'item01',CONTENT) item01,
decode(INAME,'item02',CONTENT) item02,
decode(INAME,'item03',CONTENT) item03
from tablename) group by pid;

select pid,
decode(INAME,'item01',CONTENT,null) item01,
decode(INAME,'item02',CONTENT,null) item02,
decode(INAME,'item03',CONTENT,null) item03
from tablename

select t.pos,a.content,b.content,c.content
(
select PID from dual t
)
left join item01 a on t.pid = a.pid
left join item02 b on t.pid = b.pid
left join item03 c on t.pid = c.pid