CJCoding With Joseph
15free / daySign inCreate account

How Full Each Course Is

Chain two CTEs. per_course counts the enrollments per course_id whose status is not dropped (column enrolled); fill joins that to courses and adds pct_full, the percentage of max_seats taken, rounded to 1 place. From fill, return code, enrolled, max_seats and pct_full, sorted by pct_full descending, then code. ART140 has no enrollments and does not appear.

Expected result:

+---------+----------+-----------+----------+
| code    | enrolled | max_seats | pct_full |
+---------+----------+-----------+----------+
| CS230   |       11 |        35 |     31.4 |
| ENG101  |       10 |        50 |       20 |
| MATH110 |       14 |        80 |     17.5 |
| BIO305  |        4 |        25 |       16 |
| CS101   |        9 |        60 |       15 |
| CS201   |        6 |        40 |       15 |
| CS310   |        4 |        30 |     13.3 |
| ENG250  |        4 |        30 |     13.3 |
| MATH220 |        6 |        45 |     13.3 |
| BUS150  |        9 |        90 |       10 |
+---------+----------+-----------+----------+
(showing 10 of 13 rows)
Hints3 available
Topics:
CTEs
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.