select 姓名,總分, (select count(*)+1 from 成績 s where a.總分< s.總分) as 名次 from 成績 a
在MSSQL 可用 temp table 來做
create table #tmp
(
學號 int,
姓名 varchar(50),
成績 int,
名次 int
IDENTITY(1,1)
)
insert into #tmp (學號, 姓名, 成績) select 學號, 姓名, 成績 from
table1 order by 成績 desc
select * from #tmp order by 學號
而在SQL Server 2005及Oracle 就有支援排行的函式可以用啦 該函式叫做RANK() 先記下來,改天有空再深入瞭解
近期留言