如果当天发布的输出超过5条,我想要当天发布的最早的5条,如果当天发布的数据,不够5条,我想要前一天发布的最早的来补充够五条,如果前一天发布的还不够5条,就用大前一天的数据来补充够这5条。
总的来说就5条数据。这个怎么实现,百思不得骑姐求指教

解决方案 »

  1.   

    字段只需要一个info_id,和create_date就够了吧。求指教。谢谢
      

  2.   

    先按日期降序,再按当天时间升序来排序
    select *
    from
    (select a.*,row_number() over(order by trunc(create_date,'yyyymmdd') desc,create_date asc) rn
    from tb a
    )
    where rn<=5
    ;
      

  3.   

    执行不了给个能执行的吧。脑袋乱,看不懂了。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;
      

  4.   

    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在或者,使用分析函数,如楼上这位,应该都可以吧
      

  5.   

    select * from (
    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