Window Functions · Question 10 · Medium
Window Functions question 10
Table Wallet:
txn_id | holder | amount
1 | Tara | 500
2 | Uday | 200
3 | Tara | -150
4 | Uday | 300
5 | Tara | 100
What does this query return (txn_id, balance)?
SELECT txn_id,
SUM(amount) OVER (PARTITION BY holder
ORDER BY txn_id)
FROM Wallet
ORDER BY txn_id;
- 1, 500; 2, 700; 3, 550; 4, 850; 5, 950
- 1, 450; 2, 500; 3, 450; 4, 500; 5, 450
- 1, 500; 2, 200; 3, 350; 4, 500; 5, 450
- 1, 500; 2, 200; 3, -150; 4, 300; 5, 100
Answer and explanation
Answer: C. 1, 500; 2, 200; 3, 350; 4, 500; 5, 450
Explanation: The running total restarts for each holder. Tara: 500, 500 - 150 = 350, 350 + 100 = 450 (txns 1, 3, 5). Uday: 200, 200 + 300 = 500 (txns 2, 4).
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
- Table Scores: player | team | runs Arjun | Royals | 82 Bhuvan | Royals | 82…
- Table Results: student | section | marks Aditi | A | 92 Bharti | A | 92 Chetna…
- 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…
- A table Scores(player, team, runs) is given. Why is the following query…
- Table Scores: player | team | runs Arjun | Royals | 82 Bhuvan | Royals | 82…
- Table Scores: player | team | runs Arjun | Royals | 82 Bhuvan | Royals | 82…
- Table Scores: player | team | runs Arjun | Royals | 82 Bhuvan | Royals | 82…
- Table Deposits: dep_id | day_no | amount 1 | 1 | 100 2 | 1 | 200 3 | 2 | 50 4…
- Table DailySales: day_no | amount 1 | 100 2 | 250 3 | 150 4 | 300 What does…
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