有表 visitorinfo
dottime                                                
------------------------------------------------------ 
2007-05-18 13:30:24.670
2007-05-18 13:30:24.793
2007-05-18 13:30:45.827
2007-05-18 13:30:45.890
2007-05-18 13:30:59.560
2007-05-18 13:30:59.780
2007-05-18 16:22:55.187
2007-05-18 16:32:25.233
2007-05-21 11:02:13.170我想得到结果 2007-05-18 就是点击最多的那一天咋个实现?
最好给点思路.不要只写代码.谢个啦

解决方案 »

  1.   

    select max([countvalue])
    from
    (select count([dottime]) as countvalue
    from
      visitorinfo
    group by [dottime]) as mytable子查询首先根据dottime分组计算每个dottime的个数,然后再查询出最大的一个在SQL Server 2005下通过
      

  2.   

    哦,对不起,错了,没有得到dottime,只得到了个数
    改一下:
    select top 1 [dottime],[countvalue]
    from
    (select
    [dottime],count([dottime])
    from
    visitorinfo
    group by [dottime]) as mytable
    order by [countvalue] desc
      

  3.   

    服务器: 消息 8155,级别 16,状态 2,行 11
    没有为第 2 列(属于 'mytable')指定列。
      

  4.   

    select top 1 [dottime],[countvalue]
    from
    (select
    [dottime],count([dottime]) as [countvalue]
    from
    visitorinfo
    group by [dottime]) as mytable
    order by [countvalue] desc
      

  5.   

    晕csdn把上边发的当脚本?打开页面有弹出对话啊:)嘿
      

  6.   

    嗯.我试试,
    Top  
     interboy(冯东) ( ) 信誉:100    Blog   加为好友  2007-05-21 17:09:17  得分: 0  
     
     
       就用纯日期得了,不加时间,这个时候分组就可以用了
      
     
    Top  
     interboy(冯东) ( ) 信誉:100    Blog   加为好友  2007-05-21 17:10:17  得分: 0  
     
     
       应该说正确了,是你想要的效果,你可以新建一个视图,再试图里把时间去掉,然后对试图进行操作
     
     
      

  7.   

    我知道你的问题了,你的dottime精确到了毫秒,所以一直是1
    你可以在[dottime]外加一个函数用于取dottime的yyyy-MM-dd格式,具体查一下手册吧,我手头没有...
      

  8.   

    以时间分组 当然count都是1了
      

  9.   

    select a.Tcount from
    (
    select count(to_char(dottime,'yyyy-MM-dd')) as Tcount
    from yourtable
    group by dottime
    ) a
    order by desc
      

  10.   

    赞成!
    建议用CONVERT(VARCHAR(10),dottime,50)取出日期
      

  11.   

    select a.Tcount from
    (
    select count(to_char(dottime,'yyyy-MM-dd')) as Tcount,dottime
    from yourtable
    group by dottime
    ) a
    order by desc
      

  12.   

    取出日期的天部分
    count一下“天”
    定义两个变量进行起泡算法
      

  13.   

    select  top 1 convert(varchar(10),dottime,120) as newdate,count(convert(varchar(10),dottime,120)) as countNum from visitorinfo where dottime is not null group by convert(varchar(10),dottime,120)order by convert(varchar(10),dottime,120) desc