← Back to Window Functions
Question 52
Running Total of Course Fees
Running Total of Course Fees
List the courses inidorder with a running total of their fees: returnid,code,feeandrunning_total, whererunning_totalis the sum offeeover every course from the first row up to and including the current one. UseSUM(fee) OVER (…)with an explicit frame, and sort byid.
Expected result:
+----+---------+-----+---------------+ | id | code | fee | running_total | +----+---------+-----+---------------+ | 1 | CS101 | 650 | 650 | | 2 | CS201 | 650 | 1300 | | 3 | CS230 | 700 | 2000 | | 4 | CS310 | 820 | 2820 | | 5 | MATH110 | 600 | 3420 | | 6 | MATH220 | 600 | 4020 | | 7 | ENG101 | 450 | 4470 | | 8 | ENG250 | 450 | 4920 | | 9 | BIO120 | 720 | 5640 | | 10 | BIO305 | 780 | 6420 | +----+---------+-----+---------------+ (showing 10 of 14 rows)
Hints3 available
Sign in to use hintsTopics:
Window Functions
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Ctrl+Space to expand shortcuts (sel, ins, desc)
Results
Run your SQL to see every statement's output here, then how it compares with the expected answer.
Not sure what is in a table? SHOW TABLES lists them and DESCRIBE students shows the columns — or open the database browser on the left.