
你先按那个字段倒排序,然后选择前面的五个就可以了,select
top
5
from
table
ordery
by
column
desc
declare @currMonth as DateTime
declare @prevMonth as DateTime
set @currMonth = cast(cast(year(getdate()) as varchar(4)) + right('0'+cast(month(getdate()) as varchar (2)),2) + '01' as DateTime);
set @prevMonth = DATEADD(month,-1,@currMonth)
--本月
select usid, SUM(cont) as total_cont from biao where [Time] >= @currMonth and [Time] < DATEADD(month,1,@currMonth)
group by usid
order by total_cont desc
--上月
select usid, SUM(cont) as total_cont from biao where [Time] >= @prevMonth and [Time] < @currMonth
group by usid
order by total_cont desc
如果希望用一列专门显示名次,可以使用mssql 2005提供的rank()函数。例如:本月可以这么写
select rank() over(order by sum(cont) desc) as rnk,usid, SUM(cont) as total_cont from biao where [Time] >= @currMonth and [Time] < DATEADD(month,1,@currMonth)
group by usid
order by total_cont desc
您好,提问者:
用SQL查询排序就好了。。
SELECT ,, FROM 表名 WHERE 条件 ORDER BY 要排序的字段 ASC;//ASC是升序,也就是从小到大
//DESC是降序,从大到小
以上就是关于数据库access查询设计排名并显示名次全部的内容,包括:数据库access查询设计排名并显示名次、mssql数据库asp排行统计数据(按月份查询排行)、java如何从数据库中取出数据实现排名等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)