Querying Microsoft SQL Server 2012/2014 — Question 26

Note: This question is part of a series of questions that use the same set of answer choices. An answer choice may be correct for more than one question in the series.
You create a table that has the StudentCode, SubjectCode, and Marks columns to record mid-year marks for students. The table has marks obtained by 50 students for various subjects.
You need to ensure that the following requirements are met:
✑ Students must be ranked based on their average marks.
✑ If one or more students have the same average, the same rank must be given to these students.
✑ Consecutive ranks must be skipped when the same rank is assigned.
Which Transact-SQL query should you use?

Answer options

Correct answer: A

Explanation

The correct answer is A, which uses the RANK() function to assign ranks based on the average marks, while allowing for ties and skipping ranks appropriately. Option B uses DENSE_RANK() which does not skip ranks, and options C and D do not meet the requirement of assigning the same rank to students with the same average. The other options (E, F, G, H) focus on individual scores rather than average scores across subjects, making them unsuitable for this ranking requirement.