oracle中如何用sql实现多条记录合并成一条记录?

2024-12-05 17:03:44
推荐回答(3个)
回答(1):

行转列。。。。
select * from (
(select tundishno,origin as a1 from 表 where strandid='1') a,
(select tundishno,origin as a1 from 表 where strandid='2') b,
(select tundishno,origin as a1 from 表 where strandid='3') c,
(select tundishno,origin as a1 from 表 where strandid='4') d,
(select tundishno,origin as a1 from 表 where strandid='5') e,
(select tundishno,origin as a1 from 表 where strandid='6') f

where a.tundishno =b.tundishno and a.tundishno=c.tundishno and a.tundishno=d.tundishno
and a.tundishno=e.tundishno and a.tundishno=f.tundishno
)

可以按这思路做。。。。

回答(2):

用行列转换。
select tundishno,sum(decode(STRANDID,'1', ORIGIN,null)) "1",
sum(decode(STRANDID,'2', origin,null)) "2",
sum(decode(subject,'英语', grade,null)) "3"
......
from table
group by tundishno;

回答(3):

你的要求好复杂。