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 |
mahdi87_gh
Yak Posting Veteran
72 Posts |
Posted - 2013-01-10 : 02:23:28
|
HiI have a table named QuizHistory with these fields : quizId,userId,markI want to write a query to get a user's rank for a particular quizIdThanks a lot |
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2013-01-10 : 02:56:39
|
Do you have an example (example data and wanted result)? Too old to Rock'n'Roll too young to die. |
|
|
mahdi87_gh
Yak Posting Veteran
72 Posts |
Posted - 2013-01-10 : 03:12:58
|
assume here is the records in the tablequizId, userId, mark1, 1, 851, 2, 721, 3, 941, 4, 65the rank for userId=1 would be 2 (means he is the second person in this quiz)the rank for userId=2 would be 3 (means he is the third person in this quiz) |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-01-10 : 03:22:24
|
[code]SELECT userId,Rnk FROM(SELECT DENSE_RANK() OVER (PARTITION BY quizId ORDER BY mark) AS rnk,*FROM table)tWHERE quizId=@Yourpassedquizid[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
mahdi87_gh
Yak Posting Veteran
72 Posts |
Posted - 2013-01-10 : 04:29:48
|
thanks a lot.it work's perfectly |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-01-10 : 04:35:26
|
welcome------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
|
|
|
|
|