- 相關(guān)推薦
Sql Server、Access數(shù)據(jù)排名的實現(xiàn)方法
但是,在SQL SERVER 2005 之前,SQL SERVER 2000 并沒有提供這個直接的函數(shù)供我們使用,同樣 ACCESS 也是如此。
下面我們分2種情況,來寫出數(shù)據(jù)排名的實現(xiàn)過程。測試數(shù)據(jù)如下:
Access
復(fù)制代碼 代碼如下:
select name, score, (select iif(isnull(sum(1)), 1, sum(1) + 1) from score_rank where score > a.score) as rank from score_rank a order by score desc
sqlserver
復(fù)制代碼 代碼如下:
select name, score, (select ISNULL(sum(1),0) + 1 from score_rank where score > a.score) as rank from score_rank a order by score desc
對于 SQL SERVER 2005 及更高版本
復(fù)制代碼 代碼如下:
SELECT name, score, RANK() OVER (ORDER BY score DESC) AS [rank], DENSE_RANK() OVER (ORDER BY score DESC) AS [rank1], NTILE(4) OVER(ORDER BY score DESC) AS [rank2] FROM score_rank ORDER BY score DESC;
【Sql Server、Access數(shù)據(jù)排名的實現(xiàn)方法】相關(guān)文章:
MySQL導(dǎo)出導(dǎo)入SQL文件命令方法06-29
sql語法大全03-23
養(yǎng)老保險業(yè)務(wù)數(shù)據(jù)的審計方法06-07
Sql認(rèn)證考試內(nèi)容06-08
用SQL快速生成用友GRP-U8的AO財務(wù)賬套的方法202211-10
關(guān)于JDBC連接SQL2000的詳細(xì)流程07-16