请问如何查询每年1月的数据总和,就是说条件只是月份是否为1月,年份是可以任何年的?
where后面应该怎么写?select sum(id)
from table_1
where ?????????

解决方案 »

  1.   

    select sum(id)
    from table_1
    where month(datecolumn)='1'
      

  2.   

    select convert(varchar(7),时间字段,120) as 年月, sum(id) as id 
    from table_1
    group by convert(varchar(7),时间字段,120)
    where month(时间字段) = 1
      

  3.   

    select convert(varchar(7),时间字段,120) as 年月, sum(id) as id 
    from table_1
    where month(时间字段) = 1
    group by convert(varchar(7),时间字段,120)
      

  4.   

    select Convert(Char(7),时间,120) as Mon,sum(id) as sID
    from table_1
    where Month(时间)=1 group by Convert(Char(7),时间,120)
      

  5.   

    select sum(id) 
    from table_1
    where month(时间字段) = 1
    group by convert(varchar(7),时间字段,120)