有张表叫评论表有 书ID 评论ID 评论时间 三列
求出三天内评论最多的一本书

解决方案 »

  1.   

    create table test1(id varchar2(100),comments varchar2(100),commentsdate date);insert into test1
    select '书1','fdasfdsa',sysdate-1 from dual union all
    select '书1','fdasfdsa',sysdate-2 from dual union all
    select '书1','fdasfdsa',sysdate-4 from dual union all
    select '书1','fdasfdsa',sysdate-1 from dual union all
    select '书1','fdasfdsa',sysdate-2 from dual union all
    select '书1','fdasfdsa',sysdate-3 from dual union allselect '书2','fdasfdsa',sysdate-1 from dual union all
    select '书2','fdasfdsa',sysdate-2 from dual;select * from (
    select id,count(*) c from test1 
    where sysdate-commentsdate<=3
    group by id) where rownum=1
      

  2.   

    select id,max(c) c
    from (select id,count(*) c from test1 
    where sysdate-commentsdate<=3
    group by id)a
    group by id