求前15天的每天最新断面数据(不包括当天)

来源:互联网 发布:迅雷9.0.19.482优化版 编辑:程序博客网 时间:2024/04/27 16:02

--求前15天的每天的最新断面数据(不包括当天)

with tb as (select t.id, t.gathertimefrom z_nw t where t.schemaid='YWFW003' and 1=1 and TO_CHAR(t.gathertime,'yyyy-mm-dd')     between TO_CHAR(SYSDATE-15, 'yyyy-mm-dd')     and TO_CHAR(SYSDATE-1, 'yyyy-mm-dd')order by TO_CHAR(t.gathertime,'yyyy-mm-dd') desc),tb2 as (select max(t.gathertime) gathertimefrom tb twhere 1=1group by to_char(t.gathertime,'yyyy-mm-dd'))select t.id, t.gathertime, t.columnvalue1, t.columnvalue5from z_nw t where 1=1 and t.schemaid='YWFW003' and exists (select 1 from tb2 t2 where t.gathertime = t2.gathertime);

查询结果:


0 0
原创粉丝点击