- 相關(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)文章:
SQL Server常用數(shù)據(jù)類型06-18
用SQL實現(xiàn)查詢數(shù)據(jù)不顯示錯誤數(shù)據(jù)的方法03-29
有關(guān)清除SQL Server日志的兩種方法03-29
如何更改SQL Server默認(rèn)的1433端口04-10
如何快速掌握SQL Server中的日志轉(zhuǎn)移03-29
Access 數(shù)據(jù)庫程序設(shè)計復(fù)習(xí)方法03-10
關(guān)于SQL在數(shù)據(jù)檢查中的應(yīng)用03-29