sql如何筛选出离今天最近的日期

fs82619299 2011-07-04 10:08:17
sql语句为

select distinct tr.id,
s.frate,
s.dteffective

from sett_transopenfixeddeposit tr,
sett_interestrate s

where tr.nnoticeday = s.nnotifytypeid


查询出的结果为:

ID FRATE DTEFFECTIVE
6439 1.62 2004-1-1
6439 1.88 2011-5-25
6441 1.08 2004-1-1
6441 3.2 2011-1-1

这里ID有重复的行,我需要取出列DTEFFECTIVE 距离今天最近的那条数据
就是期望的结果应该是

ID FRATE DTEFFECTIVE
6439 1.88 2011-5-25
6441 3.2 2011-1-1

请问sql语句该如何修改。
...全文
969 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
fs82619299 2011-07-05
  • 打赏
  • 举报
回复
2L 的可以用哈^_^

6L的我看不太懂···
row_number()over(partition 这几个是什么···
gelyon 2011-07-04
  • 打赏
  • 举报
回复

--分析函数很简单的
select id,frate,dteffective from (
select id,frate,dteffective,
row_number()over(partition by id order by dteffective desc) rn
from
(select distinct tr.id,s.frate,s.dteffective
from sett_transopenfixeddeposit tr,sett_interestrate s
where tr.nnoticeday = s.nnotifytypeid )
)
where rn=1;

fs82619299 2011-07-04
  • 打赏
  • 举报
回复
2L
我把括号加上了

正在试试
fs82619299 2011-07-04
  • 打赏
  • 举报
回复
3L 还是不行啊

你的语句查出的结果只有一个了
ID FRATE DTEFFECTIVE
6439 1.88 2011-5-25

fs82619299 2011-07-04
  • 打赏
  • 举报
回复
2L 缺失右括号

3L 我试下行不行

谢谢拉~
BlueskyWide 2011-07-04
  • 打赏
  • 举报
回复
手边没有工具,可以试一下:

select distinct tr.id,
s.frate,
s.dteffective
from sett_transopenfixeddeposit tr,
sett_interestrate s
where tr.nnoticeday = s.nnotifytypeid and s.dteffective in (
select max(s.dteffective) from sett_transopenfixeddeposit tr,
sett_interestrate s
where tr.nnoticeday = s.nnotifytypeid);

秋雨飘落 2011-07-04
  • 打赏
  • 举报
回复
select distinct tr.id, s.frate, s.dteffective

from sett_transopenfixeddeposit tr,
( select *
from sett_interestrate s
where s.DTEFFECTIVE =
(select max(DTEFFECTIVE)
from sett_interestrate d
where s.nnotifytypeid = d.nnotifytypeid) s

where tr.nnoticeday = s.nnotifytypeid

17,086

社区成员

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

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