SELECT MAX(today) f_day, min(today) l_day FROM (select today, row_number() over(order by today desc) rn from XXX where today between to_char(sysdate - 30, 'yyyy-mm-dd') and to_char(sysdate - 1, 'yyyy-mm-dd') group by today having(count(*)) > 5)) where rn <= 3 ORDER BY TODAY)
业务:找寻XXX表中最近一天和最近第三天的日期,当天记录数超过5行才算有效。
例如今天26号,周末没记录。
则结果为:
F_DAY L_DAY
------------------------- -------------------------
2013-02-21 2013-02-25
例如今天26号,周末没记录。
则结果为:
F_DAY L_DAY
------------------------- -------------------------
2013-02-21 2013-02-25