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

 我来答
百度网友7b87b29
推荐于2016-09-22
知道答主
回答量:40
采纳率:100%
帮助的人:19.8万
展开全部
行转列。。。。
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;
追问
我的字段是字符串,可以用sum么?我看报了一个错,“无效数字”
追答
字符串,你就先转换一下,用to_number
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
funlove999
2014-02-21 · 超过35用户采纳过TA的回答
知道答主
回答量:172
采纳率:0%
帮助的人:129万
展开全部
你的要求好复杂。
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 1条折叠回答
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式