求一SQL

tangwei070 2012-05-25 03:04:21
代码 价格 日期
001 7.01 20120501
002 5.45 20120501
003 5.68 20120502
001 7.05 20120503
003 5.45 20120503
001 7.16 20120504


要求查询结果

代码 价格 日期 代码 上次价格 日期
001 7.15 20120504 001 7.05 20120503
001 7.04 2012003 001 7.01 20120501
002 5.45 20120501
003 5.45 20120503 003 5.67 20120501
...全文
69 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
tangwei070 2012-05-25
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 的回复:]
不好意思 没按 代码分组 改后如下:

SQL code


select code,price,ctime,
lag(code) over(partition by code order by ctime) pcode,
lag(price) over(partition by code order by ctime) pprice,
……
[/Quote]

ok 结贴给分。
tangwei070 2012-05-25
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 的回复:]
不好意思 没按 代码分组 改后如下:

SQL code


select code,price,ctime,
lag(code) over(partition by code order by ctime) pcode,
lag(price) over(partition by code order by ctime) pprice,
……
[/Quote]

3Q 我去试试
tangwei070 2012-05-25
  • 打赏
  • 举报
回复
3Q 我去试试
a494910091 2012-05-25
  • 打赏
  • 举报
回复
不好意思 没按 代码分组 改后如下:

select code,price,ctime,
lag(code) over(partition by code order by ctime) pcode,
lag(price) over(partition by code order by ctime) pprice,
lag(ctime) over(partition by code order by ctime) pctime from temp_test

a494910091 2012-05-25
  • 打赏
  • 举报
回复
上次 lag函数

select code,price,ctime,
lag(code) over(order by ctime) pcode,
lag(price) over(order by ctime) pprice,
lag(ctime) over(order by ctime) pctime from temp_test
tangwei070 2012-05-25
  • 打赏
  • 举报
回复
csdn 没人了吗 擦

17,086

社区成员

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

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