Window Functions · Question 14 · Medium
Window Functions question 14
Table Scores:
player | team | runs
Arjun | Royals | 82
Bhuvan | Royals | 82
Chandan | Royals | 60
Dhawal | Titans | 95
Eknath | Titans | 40
Faisal | Titans | 71
What does this query return?
SELECT DISTINCT team,
COUNT(*) OVER (PARTITION BY team)
FROM Scores
WHERE runs >= 60
ORDER BY team;
- Royals, 3; Titans, 3
- Royals, 5; Titans, 5
- Royals, 3; Titans, 2
- Royals, 3; Royals, 3; Royals, 3; Titans, 2; Titans, 2
Answer and explanation
Answer: C. Royals, 3; Titans, 2
Explanation: WHERE runs first and removes Eknath (40), so the windows see 3 Royals rows and 2 Titans rows. Each remaining row carries its team count, and DISTINCT then reduces the 5 identical-looking rows to one per team.
Previous: Table Scores: player | team | runs Arjun | Royals | 82 Bhuvan | Royals | 82… · Next: Table Scores: player | team | runs Arjun | Royals | 82 Bhuvan | Royals | 82…
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 Scores: player | team | runs Arjun | Royals | 82 Bhuvan | Royals | 82…
- A table Scores(player, team, runs) is given. Why is the following query…
- Table Scores: player | team | runs Arjun | Royals | 82 Bhuvan | Royals | 82…
- Table Scores: player | team | runs Arjun | Royals | 82 Bhuvan | Royals | 82…
- 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 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