表(Table)结构是
id   点击次数   timetime 是包含年月日时分秒的select count(*) from Table where time>时间1 and time<时间2 group by day(time)“day(time)”这个是求出“天”的,比如day(2009-9-23 12:01:01)=23
sqlserver里有什么函数可以求出得到"2009-9-23"   呢,   上面的sqlserver语句怎么写呢,好像是没有date(2009-9-23 12:01:01)这种写法的,我的group by 要按照"2009-9-23"这样的格式来,该怎么弄,请高手帮忙看看。谢谢了。

解决方案 »

  1.   


    declare   @s   datetime   
      set   @s='2004-8-30   04:13:54'   
      select   convert(char(10),@s,120),convert(char(8),@s,114)   
      /*   
                                                
      ----------   --------     
      2004-08-30   04:13:54   
      

  2.   

    select 
      convert(varchar(10),[time],120) as [date],
      count(*) 
    from 
      [Table]
    where 
      [time]>时间1 and [time] <时间2 
    group by 
      convert(varchar(10),[time],120)
      

  3.   

    对了,再说下,我这个是access数据库,这样可以吗?到公司我测试下。看看,
      

  4.   

    select 
      convert(varchar(10),[time],120) as [date],
      count(*) 
    from 
      [Table]
    where 
      [time]>时间1 and [time] <时间2 
    group by 
      convert(varchar(10),[time],120)
      

  5.   

    access下好像没有convert函数哦。
    请各位再看看哦,谢谢哦。
      

  6.   

    是不是convert(varchar(10),[time],120)换成 Format([sTime],'yyyy-mm-dd')这个啊,好像可以哦,谢谢咯。
    回公司再测试测试。
      

  7.   

    if object_ID('tb') is not null
    drop table tb
    go
    create table tb(id datetime)
    insert into tb
    select '2009-2-23 08:10' union all
    select '2009-2-23 08:10' union all
    select '2009-2-23 08:10' union all
    select '2009-2-23 08:10' union all
    select '2009-2-23 08:10' union all
    select '2009-2-23 08:10' union all
    select '2009-2-23 08:10'
    select count(*) from tb where id>'2009-2-22' and id<'2009-2-24' group by 
    (cast((datepart(year,id)+'-'+datepart(month,id)+'-'+datepart(day,id) ) as datetime))
    结果为7
      

  8.   

    楼主朋友,如果您想按照日期的顺序进行分组,那么只能在分组时采用三个,就是year(),month(),day().虽然把日期转换到字符串形式'2009-9-23'比较方便,但是转化后的字符串分组是按照ascii码来分组的,也就是'2009-09-23'这样的数据和'2009-9-23'被认为是不用的数据.所以分组会出现问题
    select count(*) from Table where time>时间1 and time <时间2 group by year(time),month(time),day(time) 
      

  9.   

    access的?去access版那边找十三豆.
      

  10.   

    DateDiff,DateAdd,DatePart能够用于ACCESS中
      

  11.   

    select 
      convert(varchar(10),[time],120) as [date],
      count(*) 
    from 
      [Table]
    where 
      [time]>时间1 and [time] <时间2 
    group by 
      convert(varchar(10),[time],120)