Window Functions · Question 20 · Hard
Table DailySales: day_no | amount 1 | 100 2 | 250 3 | 150 4 | 300 No frame clause is written. What does this query return (day_no, value)?
SELECT day_no,
LAST_VALUE(amount) OVER (ORDER BY day_no)
FROM DailySales
ORDER BY day_no;
- 1, 300; 2, 300; 3, 300; 4, 300
- 1, NULL; 2, 100; 3, 250; 4, 150
- 1, 250; 2, 150; 3, 300; 4, NULL
- 1, 100; 2, 250; 3, 150; 4, 300
Answer and explanation
Answer: D. 1, 100; 2, 250; 3, 150; 4, 300
Explanation: With ORDER BY, the default frame ends at the current row, so the 'last value' in the frame is the current row's own amount. To get 300 on every row the frame must be extended with ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING.
Previous: 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 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…
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