3,499
社区成员
发帖
与我相关
我的任务
分享1,先按照“年月日”来排序,使用降序,保证当前天为第一条
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 *
from (select a.*,
row_number() over(order by trunc(create_date, 'yyyymmdd') desc, create_date asc) rn
from t_info a)
where rn <= 5;