For example:
Lte the table be:
SNo SudentName Marks
001 Ashok kumar 67
002 Anderson 70
003 Alfred 60
004 Ameeruddin 65
005 KalyanKumar. 69
Now the Query is: How is the 3rd ranker. The answer must be Ashok kumar.
How to write this query in SQL Server.
Query part 1: Select the top three records and ordered by marks (ASC)
Query part 2: select all records where the marks value is the MAX value of the first query part
Do you need to take into consideration, any tied value (e.g. two at 71) - how does this affect those with a score of 70?
|||SELECT TOP 1 *
FROM (SELECT TOP 3 * FROM MyTable ORDER BY Marks DESC) t1
ORDER BY Marks ASC
No comments:
Post a Comment