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 |
great_mamun
Starting Member
14 Posts |
Posted - 2011-03-22 : 03:57:39
|
Dear All,I have a table named result (user_id, total_score, exam_duration).Sample Data:user_id total_score exam_duration-------------------------------------id-1 7 00:05:00id-2 10 00:02:00id-3 10 00:10:00id-4 7 00:12:00id-5 7 00:05:00id-6 10 00:10:00id-7 6 00:07:45id-8 9 00:09:45id-9 6 00:13:23id-10 4 00:12:20Expected_Ouput:Rank user_id total_score exam_duration---------------------------------------------1 id-2 10 00:02:00 -> eql score but less time2 id-3 10 00:10:00 -> both eql 2 id-6 10 00:10:00 -> both eql so same rank3 id-8 9 00:09:454 id-1 7 00:05:00 -> both eql 4 id-5 7 00:05:00 -> both eql so same rank5 id-4 7 00:12:00 -> eql score but more time6 id-7 6 00:07:45 -> eql score but less time7 id-9 6 00:13:23 -> eql score but more time8 id-10 4 00:12:20 -> less scoreWhat I want, order by total_score desc, if equal then sort by exam_duration asc , if both equal then same rank....I would highly appreciate if you would plz give the sql query (only sql query) Best Regards,Abdullah Al Mamun |
|
pk_bohra
Master Smack Fu Yak Hacker
1182 Posts |
Posted - 2011-03-22 : 04:04:50
|
Can you show us what you have tried ?Hint for you to start with: Use Dense Rank function order by total_score desc and exam_duration asc |
 |
|
|
|
|