表名A表结构:
id   username          ip             startTime            isMessage
1      210          202.176.22.1   2009-7-8 10:57:00      2
2      210          202.176.22.1   2009-7-8 10:20:00      1
3      210          202.176.22.1   2009-7-6 10:20:00      0
4      210          202.176.22.2   2009-7-8 10:20:00      0
5      210          202.176.22.3   2008-7-2 10:20:00      0要的结果是:把username=210的每天里面不重复的IP数量最多的查询出来,(这里2009-7-8号是不重复IP数最多的,只显示IP不重复最多的),显示年-月-日,和这一天不重复的IP总个数count(distinct ip),以及这一天的isMessage的总和sum(isMessage)                startTime  CountIP    SumIsMessage      
这里的结果是显示:2009-7-8   2          3
                 
各位老大一定要帮帮我啊,我做了很久一直做不出来~!~!

解决方案 »

  1.   

    试试:select char(startTime,'yyyy-mm-dd'), count(distinct ip), sum(isMessage) from a 
    where username=210 and to_char(starttime,'yyyy-mm-dd')=
    (select st from (select char(startTime,'yyyy-mm-dd') st, count(distinct ip) countip from a where username=210 group by char(startTime,'yyyy-mm-dd')  order by count(distinct ip) desc ) where rownum<2)
    group by char(startTime,'yyyy-mm-dd')
      

  2.   

    几个char笔误,改为to_char:select to_char(startTime,'yyyy-mm-dd'), count(distinct ip), sum(isMessage) from a 
    where username=210 and to_char(starttime,'yyyy-mm-dd')= 
    (select st from (select to_char(startTime,'yyyy-mm-dd') st, count(distinct ip) countip from a where username=210 group by to_char(startTime,'yyyy-mm-dd')  order by count(distinct ip) desc ) where rownum <2) 
    group by to_char(startTime,'yyyy-mm-dd')