oracle 取最近一天数据

hp2008001 2010-07-28 05:13:39
遇到个问题

怎样取得最近一天数据

有个时间字段 TS

...全文
668 17 打赏 收藏 转发到动态 举报
写回复
用AI写文章
17 条回复
切换为时间正序
请发表友善的回复…
发表回复
Harvey121 2010-12-03
  • 打赏
  • 举报
回复
select * from (select * from tb order by TS desc ) where ROWNUM=1

Harvey121 2010-12-03
  • 打赏
  • 举报
回复
oracle 不太会!写出的语句不要笑话我昂...
不过我的理解是这样的:
例如:你最近一次(天?)吸烟是在什么时候?
select * from tb where f_date=(select max(TS) from tb )






WXHDSWH 2010-09-20
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 wkc168 的回复:]
引用楼主 hp2008001 的回复:
遇到个问题

怎样取得最近一天数据

有个时间字段 TS


SQL code


select *
from (select a.*,row_number over(order by ts desc) rn from tb) where a.rn=1
[/Quote]
支持下
fly2749 2010-09-17
  • 打赏
  • 举报
回复
[Quote=引用 12 楼 minitoy 的回复:]

需求不明确.
1楼或者6楼吧
[/Quote]
确实不明确,楼主是不是想要取所有日期中最后一天的信息
minitoy 2010-09-16
  • 打赏
  • 举报
回复
需求不明确.
1楼或者6楼吧
bai405bai 2010-09-16
  • 打赏
  • 举报
回复
好东西学习了
lanmengxjh 2010-07-28
  • 打赏
  • 举报
回复
select * from (select a.*,row_number() over(order by ts desc) rn from tb) where rn=1
minitoy 2010-07-28
  • 打赏
  • 举报
回复
。。。。
我是没看明白楼主的需求
gelyon 2010-07-28
  • 打赏
  • 举报
回复
或者这样:
select * from tab where ts between trunc(sysdate)+1/86400 and trunc(sysdate+1)-1/86400 ;
gelyon 2010-07-28
  • 打赏
  • 举报
回复
楼上的SQL语句获得的数据不准确,还是用我的吧
luoyoumou 2010-07-28
  • 打赏
  • 举报
回复
-- 最近一天的:直接用 sysdate-1 就OK啦!
-- (即24个小时前,到现在的数据,如果你的时间字段,没有比当前时间还大的数据记录行在在的话)
select * from tab where ts>= sysdate-1;
gelyon 2010-07-28
  • 打赏
  • 举报
回复
上面的格式写错了:
这个试试
select * from table where versions between timestamp to_timestamp(trunc(sysdate)+1/86400,'yyyymmdd hh24:mi:ss') and to_timestamp(trunc(sysdate+1)-1/86400,'yyyymmdd hh24:mi:ss') ;
心中的彩虹 2010-07-28
  • 打赏
  • 举报
回复
[Quote=引用楼主 hp2008001 的回复:]
遇到个问题

怎样取得最近一天数据

有个时间字段 TS
[/Quote]


select *
from (select a.*,row_number over(order by ts desc) rn from tb) where a.rn=1





gelyon 2010-07-28
  • 打赏
  • 举报
回复
select * from table where versions between timestamp to_timestamp(trunc(sysdate)+1/86400,'yyyymmdd') and to_timestamp(trunc(sysdate+1)-1/86400,'yyyymmdd') ;
zzbinfo 2010-07-28
  • 打赏
  • 举报
回复
select * from 表名 where TS between '日期' and '日期'
Phoenix_99 2010-07-28
  • 打赏
  • 举报
回复
select * from tab where ts>=trunc(sysdate)-1

17,377

社区成员

发帖
与我相关
我的任务
社区描述
Oracle 基础和管理
社区管理员
  • 基础和管理社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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