三个字段:name,count,time 假如分别表示:姓名,吃了方便面袋数,吃方便面时间。 当一个人吃了方便面时插入一条记录:姓名,吃了几袋,当前时间;形如: ('zzz',2,'2009-04-09 23:09:09')。 题目:找出某段时间内吃了方便面最多的人。(假设一个月吧,2009-4-1到2009-4-30)。 

解决方案 »

  1.   


    select NameCount,name
    (select count(name) NameCount,name
    from tableName
    where time between '2009-4-1' and '2009-4-30'
    group by name
    order by count(name) desc
    )
    where rownum = 1
      

  2.   

    select name,max(count) count,time
    from table 
    where time>=to_date('2009-4-1','yyyy-mm-dd')
      and time<=to_date('2009-4-30','yyyy-mm-dd')
    group by name,time
      

  3.   

    select 姓名
    from
    (
    select 姓名,sum(数量)
    from ttt2
    where 时间 between to_date('2009-04-01','yyyy-mm-dd') and to_date('2009-04-30','yyyy-mm-dd')
    group by 姓名
    order by sum(数量) desc) where rownum=1
      

  4.   

    谢谢大家,最终我发现这个可以:
    select name 
    from
    (
    select name  from TEST 
    where time between to_date('2009-04-01','yyyy-mm-dd') and to_date('2009-04-30','yyyy-mm-dd')
    group by name 
    order by sum(value) desc
    )
    where rownum=1
    欢迎大家提出更好的解决方法