Window Functions · Question 17 · Hard

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
                         ROWS BETWEEN 1 PRECEDING AND CURRENT ROW)
FROM DailySales
ORDER BY day_no;
  1. 1, 100; 2, 350; 3, 400; 4, 450
  2. 1, 100; 2, 350; 3, 500; 4, 800
  3. 1, 350; 2, 400; 3, 450; 4, 300
  4. 1, 350; 2, 500; 3, 700; 4, 450
Answer and explanation

Answer: A. 1, 100; 2, 350; 3, 400; 4, 450

Explanation: The frame is the previous row and the current row, a 2-day moving sum. Day 1 has no previous row, so it is 100; then 100 + 250 = 350, 250 + 150 = 400 and 150 + 300 = 450.

Previous: Table Deposits: dep_id | day_no | amount 1 | 1 | 100 2 | 1 | 200 3 | 2 | 50 4… · 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