Course completion rate
Mediumsqlgroup bycaseaggregate
progress holds each learner's percentage (0–100) per course. For each course_id return learners (the count) and completed_pct = the percentage with percent = 100, rounded to one decimal. Sort by course_id.
Tables
- progress (student_id INTEGER, course_id INTEGER, percent INTEGER)
Example 1
progress
| student_id | course_id | percent |
|---|---|---|
| 1 | 1 | 100 |
| 2 | 1 | 40 |
| 3 | 1 | 100 |
| 1 | 2 | 10 |
Expected result
| course_id | learners | completed_pct |
|---|---|---|
| 1 | 3 | 66.7 |
| 2 | 1 | 0 |
Constraints
- 0 ≤ rows ≤ 1000
- The order of rows matters
Submit checks your solution against 7 tests, including hidden ones.
SQL
-- Write one SELECT query. Tables: progress SELECT