Sql2000 處理排名中存在並列排名的問題

2021-04-19 06:29:49 字數 1035 閱讀 9856

其實這個問題不難,不過今天碰上了,就記下來,權當做筆記,呵呵。

案例,做乙個奧運排行榜,根據金,銀,銅牌的獎牌數來排名,3種獎牌相同的時候排名並列。只有乙個表,表結構如下:

create table t_medal

(country varchar(50) primary key, -- 國家名

glod int, -- 金牌數

silver int, -- 銀牌

bronze int -- 銅牌數

)要求,列出獎牌排行榜(sql2005已經有這個語句,sql2000還沒有)。

我是這樣處理的,儲存過程:

/*獲得獎牌排行榜

2008-07-31

*/create procedure p_medal_list

asset nocount on

-- 建立臨時表,下面會用rownum來做排名

declare @tmptb table

(rownum int identity(1,1), -- 做排名用

glod int,

silver int,

bronze int

)-- 找出所有的獎牌情況,並按獎牌多少排名

insert into @tmptb(glod,silver,bronze)

select distinct glod,silver,bronze from t_medal

group by glod,silver,bronze

order by glod desc,silver desc,bronze desc

select a.country,a.glod,a.silver,a.bronze,b.rownum

from t_medal a inner join @tmptb b

on a.glod = b.glod and a.silver = b.silver and a.bronze = b.bronze

order by b.rownum asc

go就這樣,雖然沒有sql2005那麼簡單,但是也不是很複雜。

SQL2000和SQL2005的行轉列處理方法

select show id year n1 n2 n3 n4 n5 from datapass db dbo test 1 sql2005中的列轉行.select show id mon,subtotal from datapass db dbo test unpivot subtotal for...

SQL2000和SQL2005的行轉列處理方法

sql2000和sql2005的行轉列處理方法 2007 10 26 09 24 原表結構 select show id year n1 n2 n3 n4 n5 from datapass db dbo test 1 sql2005中的列轉行.select show id mon,subtotal ...

修復SQL2000中損壞的表

修復sql2000中損壞的表 在查詢分析器執行 select from barcode 提示伺服器 訊息 3624,級別 20,狀態 1,行 1 location recbase.cpp 1371 expression m nvars 0 spid 52 process id 776 連線中斷 然後...