根据表内分数降序排列,显示用户名,大类,小类
1 SET ANSI_NULLS ON 2 GO 3 SET QUOTED_IDENTIFIER ON 4 GO 5 6 CREATE PROCEDURE S_GetScoreRank 7 @timestart datetime, 8 @timeend datetime 9 AS 10 BEGIN 11 select * 12 from( 13 SELECT 14 S_UserNum as u, 15 SUM (S_Score) as s, 16 S_BigClass as bc, 17 S_SmallClass as sc from S_Matter 18 where 19 @timestart<=S_PlanStart 20 and @timeend>=S_PlanStart 21 group by S_UserNum,S_BigClass,S_SmallClass 22 )as c 23 order by s desc 24 END 25 GO
若要按本月的发生的事件进行查询时可以 使用
Where DateDiff(mm,[Create on], GetDate()) = 0
上个月1 下个月-1
其他时间同上