三个字段, 日期, ID, 次数时间字段为 yyyy-MM-dd hh:mm:00只查时间 ID 日期例如: ID:001  日期:2007-04-17 18:12:00 (不要时间,只查询日期)查询以上两个条件,计算出 2007-04-17 001 这个ID 的次数总合我这样写,能查询出来但不计算次数总合,我现在查询出来的效果是例如ID       日期                    次数
001      2007-04-17 15:10:00     20
001      2007-04-17 16:12:00     20
001      2007-04-17 12:04:00     20
001      2007-04-17 18:55:00     20
001      2007-04-17 13:34:00     20
我需要的效果是ID       日期                    次数
001      2007-04-17(时间不显示)  100
也就是说计算出总合
我是这样写的
Select Sum(次数),ID,日期 From 表 Where ID = '001' and (convert(char(10),日期,120) = '2007-04-17') Group By ID,日期

解决方案 »

  1.   

    (convert(char(10),日期,120) = '2007-04-17')
    直接写成 日期='2007-04-17' 不行?
    手上无可用资源,无法调试
      

  2.   

    Select Sum(次数),ID,convert(char(10),日期,120) as new日期 From 表 Where ID = '001' and (convert(char(10),日期,120) = '2007-04-17') Group By ID,convert(char(10),日期,120)
      

  3.   

    Select Sum(次数),ID,convert(char(10),日期,120) as new日期 From 表 Where ID = '001' and (convert(char(10),日期,120) = '2007-04-17') Group By ID,convert(char(10),日期,120)
      

  4.   

    Select   Sum(次数),ID,convert(char(10),日期,120)   as   new日期   From   表   Where   ID   =   '001 '   and   (convert(char(10),日期,120)   =   '2007-04-17 ')   Group   By   ID,convert(char(10),日期,120)
      

  5.   

    Select   Sum(次数),ID,convert(char(10),日期,120)   as   new日期   From   表   Where   ID   =   '001 '   and   (convert(char(10),日期,120)   =   '2007-04-17 ')   Group   By   ID,convert(char(10),日期,120) 
     
    这种可行