select convert(char(7),t_date,120),sum(t_money)
from yourTable
group by convert(char(7),t_date,120)

解决方案 »

  1.   

    不是所有的高級語言都有float類型,
      

  2.   

    1.表Table中有两字段t_date(datetime)和t_money(money)
    t_date格式为:yyyy-mm-dd
    ---------------------------------------
    现要求对同一个月的t_money进行求和.
    并按月份列出记录.--查询语句
    select 年月=convert(char(7),date,120),合计=sum(t_money)
    from table
    group by  convert(char(7),date,120)
    --2.money型和高级语言中那一种类型兼容?(float)
    和decimal/numeric兼容
      

  3.   

    select year(getdate()) as 年,month(getdate()) as 月,sum(t_money) as 合计 from table group by year(getdate()),month(getdate())
      

  4.   

    select 周数=datediff(wk,t_date,getdate()),合计=sum(t_money)
    from table
    group by  datediff(wk,t_date,getdate()),
      

  5.   

    改正一下我的错误.
    select year(t_date)as 年,month(t_date) as 月,sum(t_money) as 合计 from table group by year(t_date),month(t_date)