Window Functions · Question 19 · Hard
Window Functions question 19
Table Scores:
player | team | runs
Arjun | Royals | 82
Bhuvan | Royals | 82
Chandan | Royals | 60
Dhawal | Titans | 95
Eknath | Titans | 40
Faisal | Titans | 71
The query uses GROUP BY and a window function together. What does it return?
SELECT team,
SUM(runs),
RANK() OVER (ORDER BY SUM(runs) DESC)
FROM Scores
GROUP BY team
ORDER BY team;
- Royals, 224, 2; Titans, 206, 1
- Royals, 224, 1; Titans, 206, 2
- Royals, 224, 1; Titans, 206, 1
- Nothing; a window function cannot be used in a query that has GROUP BY
Answer and explanation
Answer: B. Royals, 224, 1; Titans, 206, 2
Explanation: GROUP BY runs first and produces two rows: Royals 224 and Titans 206. Window functions are evaluated after grouping, so RANK simply ranks those two group totals.
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 No frame…
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
- Table Deposits: dep_id | day_no | amount 1 | 1 | 100 2 | 1 | 200 3 | 2 | 50 4…
- Table DailySales: day_no | amount 1 | 100 2 | 250 3 | 150 4 | 300 What does…
- Table Scores: player | team | runs Arjun | Royals | 82 Bhuvan | Royals | 82…
- Table DailySales: day_no | amount 1 | 100 2 | 250 3 | 150 4 | 300 No frame…
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