Window Functions · Question 4 · Easy

Window Functions question 4

Table Scores:
player | team | runs
Arjun | Royals | 82
Bhuvan | Royals | 82
Chandan | Royals | 60
Dhawal | Titans | 95
Eknath | Titans | 40
Faisal | Titans | 71

How many rows does this query return?

SELECT team,
       SUM(runs) OVER (PARTITION BY team)
FROM Scores;
  1. 1 row
  2. 2 rows
  3. 3 rows
  4. 6 rows
Answer and explanation

Answer: D. 6 rows

Explanation: A window function does not collapse rows. Every one of the 6 rows is returned, each carrying its team total; GROUP BY team would have returned 2 rows.

Previous: Table DailySales: day_no | amount 1 | 100 2 | 250 3 | 150 4 | 300 What does… · Next: What does PARTITION BY do inside an OVER clause?

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