CJCoding With Joseph
15free / daySign inCreate account

Running Total of Course Fees

List the courses in id order with a running total of their fees: return id, code, fee and running_total, where running_total is the sum of fee over every course from the first row up to and including the current one. Use SUM(fee) OVER (…) with an explicit frame, and sort by id.

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
Topics:
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.