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;
  1. Royals, 3; Titans, 3
  2. Royals, 5; Titans, 5
  3. Royals, 3; Titans, 2
  4. 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

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