Window Functions · Question 3 · Easy

Table DailySales: day_no | amount 1 | 100 2 | 250 3 | 150 4 | 300 What does this query return (day_no, total)?

SELECT day_no,
       SUM(amount) OVER (ORDER BY day_no)
FROM DailySales
ORDER BY day_no;
  1. 1, 800; 2, 800; 3, 800; 4, 800
  2. 1, 100; 2, 350; 3, 500; 4, 800
  3. 1, 100; 2, 250; 3, 150; 4, 300
  4. 1, 100; 2, 350; 3, 400; 4, 450
Answer and explanation

Answer: B. 1, 100; 2, 350; 3, 500; 4, 800

Explanation: With ORDER BY inside OVER, SUM becomes a running total: each row gets the sum of all rows up to and including itself. 100, then 100 + 250 = 350, then 500, then 800.

Previous: Table DailySales: day_no | amount 1 | 100 2 | 250 3 | 150 4 | 300 What does… · 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