+ -
当前位置:首页 → 问答吧 → oracle查询问题,望指教

oracle查询问题,望指教

时间:2011-11-07

来源:互联网

数据库中的数据是:

一天中有不同时间段的数据,也就是说一天中有很多条数据,

我现在想要查询的是每天或者是指定哪几天中的最后的时间的一条数据

如何写sql语句???

比如说表ha01中有字段dtime(日期带时间),fa(数据1)

select t.dtime,t.fa from ha01 t

然后怎么加条件?

作者: fengxiao198711   发布时间: 2011-11-07

SQL code

-- 查询2011年10月31日的最后时间数据
select t.dtime,t.fa 
from ha01 t
where t.dtime = (select max(dtime) from ha01 where to_char(dtime,'yyyymmdd') = '20111031');


作者: xiaobn_cn   发布时间: 2011-11-07

select t.dtime,t.fa from ha01 t
 where t.dtime in
  (select max(dtime)
  from ha01 
  where dtime between to_date(dtime, 'yyyy-mm-dd') and
  to_date(dtime, 'yyyy-mm-dd'))

作者: programmerxiaocai   发布时间: 2011-11-07

with a as 
(select t.unitime, row_number() over (partition by to_char(t.unitime, 'yyyymmdd') order by t.unitime desc)as rownumber 
from ha01 t)
select a.unitime from a
where a.rownumber = 1;

作者: yixilan   发布时间: 2011-11-07