oracle中如何用sql实现多条记录合并成一条记录?
3个回答
展开全部
行转列。。。。
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
)
可以按这思路做。。。。
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
)
可以按这思路做。。。。
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2014-02-21
展开全部
用行列转换。
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;
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;
追问
我的字段是字符串,可以用sum么?我看报了一个错,“无效数字”
追答
字符串,你就先转换一下,用to_number
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
你的要求好复杂。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询