跪求大婶帮忙,sql两列数据合并为一行

淡悸优伤 2015-08-18 08:27:56


改为
id num id num
102 1 102 2
102 3 102 4
102 5 102 6
102 7 102 8
...全文
221 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
淡悸优伤 2015-08-19
  • 打赏
  • 举报
回复
已解决 多谢 select a.flight_airline_direction_seq, b.flight_airline_direction_seq, a.flight_airline_id from (select flight_airline_id, flight_airline_direction_seq from naip2015_04.flight_airline_point0 t where FLIGHT_AIRLINE_ID = 102 and mod(FLIGHT_AIRLINE_DIRECTION_SEQ, 2) = 1) a, (select flight_airline_id, flight_airline_direction_seq from naip2015_04.flight_airline_point0 d where FLIGHT_AIRLINE_ID = 102 and mod(FLIGHT_AIRLINE_DIRECTION_SEQ, 2) = 0) b where a.flight_airline_id = b.flight_airline_id and a.flight_airline_direction_seq + 1 = b.flight_airline_direction_seq
引用 3 楼 mayanzs 的回复:
如果不需计算,那用lead函数很方便

select id1,num1,id2,num2 from 
    (select id id1,num num1,lead(id,1,'') over (order by num) id2,lead(num,1,0) over(order by num) num2,rownum rn from YourTable)
  where mod(rn,2)=1
如果需并成6列,则在select后面增加id3,num3,并将mod(rn,2)=1改成mod(rn,3)=1即可
mayanzs 2015-08-19
  • 打赏
  • 举报
回复
如果不需计算,那用lead函数很方便

select id1,num1,id2,num2 from 
    (select id id1,num num1,lead(id,1,'') over (order by num) id2,lead(num,1,0) over(order by num) num2,rownum rn from YourTable)
  where mod(rn,2)=1
如果需并成6列,则在select后面增加id3,num3,并将mod(rn,2)=1改成mod(rn,3)=1即可
_Kem 2015-08-18
  • 打赏
  • 举报
回复
引用 1 楼 jdsnhan 的回复:
你给的示例明显是4行,不是一行啊
虽然我不知道怎么改,但是我明白楼主的意思、 人家那是4“列”。。。不是4行
jdsnhan 2015-08-18
  • 打赏
  • 举报
回复
你给的示例明显是4行,不是一行啊

17,086

社区成员

发帖
与我相关
我的任务
社区描述
Oracle开发相关技术讨论
社区管理员
  • 开发
  • Lucifer三思而后行
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧