一共两列
id  time
1   201009
2   201009
3   201009
1   201009
1   201009
2   201009
4   201009
求,,某一时间点击量最大的id号?(oracle)

解决方案 »

  1.   

    select time,max(id) from tablename
    group by time
      

  2.   

    select id,time,max(id) keep(dense_rank last order by count(*)) 最大id
    from tb
    where time between t1 and t2
    group by id,time
      

  3.   

    select max(id) from tb where time =某一时间
      

  4.   

    select id,time from
    (
    select id,count(id) num,time from table
    where time = '某一时间'
    group by time,id
    order by num desc
    )
    where rownum =1;
      

  5.   

    select id from
    (
    select id,count(id) num,time from table
    where time = '某一时间'
    group by time,id
    order by num desc
    )
    where rownum =1;
      

  6.   


    --前面的修正下
    SQL> edi
    已写入 file afiedt.buf  1  select max(id) keep(dense_rank last order by count(*))
      2  from tb
      3  where time ='201009'
      4* group by id
    SQL> /MAX(ID)KEEP(DENSE_RANKLASTORDERBYCOUNT(*))
    ------------------------------------------
                                             1
      

  7.   

    time没用处 干脆去掉吧
    select id from
    (
    select id,count(id) num from table
    where time = '某一时间'
    group by id
    order by num desc
    )
    where rownum =1;
      

  8.   

    这个可以:
    select time,max(id) 
      from tablename
     group by time
      

  9.   

    查询所有时间的最大ID列表:
    select time,max(id) from tablename group by time
    查询某一个时间点,例如201009的最大ID
    select max(id) from tablename where time='201009'
      

  10.   

    select b.id,max(b.a) from (select time,id,count(*) a  from tablename where time='yyyy-mm-dd' group by time,id ) b group by b.id