如果当天发布的输出超过5条,我想要当天发布的最早的5条,如果当天发布的数据,不够5条,我想要前一天发布的最早的来补充够五条,如果前一天发布的还不够5条,就用大前一天的数据来补充够这5条。
总的来说就5条数据。这个怎么实现,百思不得骑姐求指教
总的来说就5条数据。这个怎么实现,百思不得骑姐求指教
解决方案 »
- oracle存储过程
- ORACLE9.2.7,用D:\oracle\oradata目录下的文件,如何恢复数据库?请高手指点
- 我想22:50分执行这个作业,不知道如何设置参数……
- 高分求救!如何解决回滚段太小问题?急,急,急,急!
- 同时安装Oracle devoloper suit 10 与Oracle 10数据库的问题
- 大家好,请教大家一个如何学习的问题,请大家帮帮忙!
- 第三列等于前两列的计算结果,但前两列也是子查询怎么做
- 一个新手的问题?
- 保存数据时出错:
- oracle创建了一个无密码验证的dblink,是怎么通过无密码验证的
- 关于学习oracle rac的菜鸟问题
- ld: 0711-317 ERROR: Undefined symbol: .trim
select *
from
(select a.*,row_number() over(order by trunc(create_date,'yyyymmdd') desc,create_date asc) rn
from tb a
)
where rn<=5
;
from (select a.*,
row_number() over(order by trunc(create_date, 'yyyymmdd') desc, create_date asc) rn
from t_info a)
where rn <= 5;
2,然后再每一天中,按照时间来排序,使用升序,保证最早的日期为第一条。
好像就可以了吧:
sql如下:
select * from (
select * from table1 order by trunc(create_date,'yyyyMMdd') desc,trunc(create_date,'hh24miss') asc
) where rownum < 6或者
select * from (
select * from table1 order by to_char(create_date,'yyyyMMdd') desc,to_char(create_date,'hh24miss') asc
) where rownum < 6在或者,使用分析函数,如楼上这位,应该都可以吧
select info_id,create_date,rownum rn,rnb from
(select info_id,create_date, rownumber()over(partition by trunc(create_date,'yyyymmdd') order by create_date) rnb from tb) order by trunc(create_date,'yyyymmdd') desc,rnb
)
where rn<=5