--的确没考虑年.: )
declare @t table(用户名 varchar(20),积分 int,时间 datetime)
insert into @t select 'aaa',2,'2006-7-9 13:00:12'
union all select 'bbb',3,'2006-7-6 13:00:12'
union all select 'ccc',3,'2006-7-4 13:00:12'
union all select 'aaa',5,'2006-7-9 13:00:12'
union all select 'ccc',1,'2006-7-4 13:00:12'
union all select 'ccc',1,'2007-7-4 13:00:12'
select 用户名=用户名,积分=sum(积分)
from @t
where datediff(month,时间,{fn now()})=0 and datediff(year,时间,{fn now()})=0
group by 用户名
order by sum(积分) desc
Create Table TEST
(用户名 Varchar(10),
积分 Int,
时间 DateTime)
Insert TESt Select 'aaa', 2, '2006-7-9 13:00:12'
Union All Select 'bbb', 3, '2006-7-6 13:00:12'
Union All Select 'ccc', 3, '2006-7-4 13:00:12'
Union All Select 'aaa', 5, '2006-7-9 13:00:12'
Union All Select 'ccc', 1, '2006-7-4 13:00:12'
GO
Select
用户名,
SUM(积分) As 积分
From TEST
Where Convert(Varchar(7),时间,120)=Convert(Varchar(7),GetDate(),120)
Group By 用户名
Order By 积分 Desc
GO
Drop Table TEST
--Result
/*
用户名 积分
aaa 7
ccc 4
bbb 3
*/