Window Functions · Question 8 · Medium

Window Functions question 8

Table Results:
student | section | marks
Aditi | A | 92
Bharti | A | 92
Chetna | A | 85
Divya | B | 75
Ekta | B | 81
Fatima | B | 78

What does this query return?

SELECT student,
       DENSE_RANK() OVER (PARTITION BY section
                          ORDER BY marks DESC)
FROM Results
ORDER BY student;
  1. Aditi, 1; Bharti, 1; Chetna, 3; Divya, 3; Ekta, 1; Fatima, 2
  2. Aditi, 1; Bharti, 1; Chetna, 2; Divya, 5; Ekta, 3; Fatima, 4
  3. Aditi, 1; Bharti, 2; Chetna, 3; Divya, 3; Ekta, 1; Fatima, 2
  4. Aditi, 1; Bharti, 1; Chetna, 2; Divya, 3; Ekta, 1; Fatima, 2
Answer and explanation

Answer: D. Aditi, 1; Bharti, 1; Chetna, 2; Divya, 3; Ekta, 1; Fatima, 2

Explanation: Ranking restarts in each section. In A, the two 92s share rank 1 and DENSE_RANK leaves no gap, so Chetna is 2. In B the order is Ekta 81, Fatima 78, Divya 75, giving 1, 2, 3.

Previous: Table Scores: player | team | runs Arjun | Royals | 82 Bhuvan | Royals | 82… · Next: Table DailySales: day_no | amount 1 | 100 2 | 250 3 | 150 4 | 300 What does…

Practise window functions

Try a fresh set of window functions questions with an explanation after every answer, free and without signing up: Window Functions practice. Or sit a full placement mock test.

More window functions questions

More sql practice

NULL Handling · SQL Functions & CASE · UNION, INTERSECT & EXCEPT · Tables, Keys & Constraints · DML & Transactions · SELECT, WHERE & ORDER BY · SQL Joins · Aggregates & GROUP BY

LogicWiz Exams home · All practice topics · Placement mock tests · Daily 10 challenge