select sum(money) from table where year(datetime)=year(taday()) and month(datetime)=month(taday()) group by datetime
select sum(money) as je where month(datetime)=所要的月份
select sum(金额) as 本月 from tablename where datediff(month,getdate(),字段日期)=0 select sum(金额) as 本年 from tablename where datediff(year,getdate(),字段日期)=0
select sum(money) form where month(datetime)=month(getdate())
落了点东西select sum(money) as je from 表名 where month(datetime)=所要的月份
select sum(money) as 本月 from tablename where month(datetime)=month(getdate())//本月的 select sum(money) as 本年 from tablename where year(datetime)=year(getdate())//本年的
参考一下吧:select sum(money) from 表格 where datetime between (dateadd(d,-datepart(d,getdate()),getdate()),gettime())
最笨的方法是通过convert把dcatetime转变成varchar. 在sum(money)也可以select sum(money) from ## where datepart(year,datetime)=datepart(year,getdate()) and datepart(month,datetime)=datepart(month,getdate())
from table
where year(datetime)=year(taday()) and
month(datetime)=month(taday())
group by datetime
from tablename
where datediff(month,getdate(),字段日期)=0
select sum(金额) as 本年
from tablename
where datediff(year,getdate(),字段日期)=0
select sum(money) as 本年 from tablename where year(datetime)=year(getdate())//本年的
在sum(money)也可以select sum(money) from ## where datepart(year,datetime)=datepart(year,getdate()) and datepart(month,datetime)=datepart(month,getdate())