Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
Keshaba
Yak Posting Veteran
52 Posts |
Posted - 2008-12-09 : 06:31:52
|
I am using Sql server 2005 express .I want to write a query where I can get Top 10 marks as well as I want to rank them 1, 2, 3.The ranking should be best on the order of marks obtained.I can write the Top 10 query as follows but I don't know how to rank them .I tried like thisselect TOP 10 Marks from mark_up order by Marks descBut I want the answer to come like thisRank Marks1 1002 602 603 454 355 30 Keshab |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-12-09 : 06:55:41
|
[code]DECLARE @Top TABLE ( Rank INT, Marks INT )INSERT @TopSELECT 1, MarkFROM Table1UPDATE tSET t.Rank = (SELECT COUNT(DISTINCT Marks) FROM @Top AS x WHERE x.Marks >= t.Marks)FROM @Top AS tSELECT *FROM @TopORDER BY Rank[/code] E 12°55'05.63"N 56°04'39.26" |
|
|
|
|
|