一个 tongji表,
leibie  jine      riqi
A       100     2010-1-2
B       10      2010-1-1
A       50      2010-1-20
C       20      2010-1-5
根据日期的范围  分组统计类别 要查A 的金额总和 怎么写?
select leibie,sum(jine) as oof  from tongji group by leibie    这样写能读取数据 但加上时间条件后语法错误。。哪位知道的帮忙解惑

解决方案 »

  1.   

    select from where group by试试
      

  2.   

    where 子句在 group by 前面,注意不同的数据库日期表示形式不同
    Access: where riqi = #2010-1-2#
    SQL Server: where riqi = '2010-1-2'
      

  3.   

    group by 可以,, 但时间怎么加??  我用AND 和HAVING都说语法错误···
      

  4.   

    SELECT leibie,Sum(jine) As oof
    FROM tongji 
    GROUP BY leibie,riqi
     注意:你的riqi字段的类型,不能是Text ,一定要是 Date
      

  5.   

    select leibie,sum(jine) as oof from tongji where riqi >'2010-1-1' and riqi <'2010-1-30' group by leibie 
      

  6.   

    如果你想 where 时间,请在 Group By 语句前使用 Where