Distinction Apprentices
Problem
An apprenticeship scheme records data in apprentices(apprentice_id, full_name, trade), units(unit_id, title, weeks, trade, core) where core is 'Yes' or 'No', and records(apprentice_id, unit_id, cohort, mark, score). An apprentice earns a distinction when they meet ALL of these conditions within their own trade: they took every core unit of their trade and scored mark 'A' in each; they took at least two optional (non-core) units of their trade and scored at least 'B' (i.e. 'A' or 'B') in each of those optional units they took; and their overall average score across all their records is at least 2.5. Return the apprentice_id of each qualifying apprentice, ordered ascending.
Tables
Example rows — the live problem includes the full dataset.
| apprentice_id | full_name | trade |
|---|---|---|
| 1 | Nadia | Plumbing |
| 2 | Omar | Plumbing |
| 3 | Priya | Welding |
| unit_id | title | weeks | trade | core |
|---|---|---|---|---|
| 101 | Pipe Fitting | 3 | Plumbing | Yes |
| 102 | Drainage | 3 | Plumbing | Yes |
| 103 | Arc Basics | 4 | Welding | Yes |
| apprentice_id | unit_id | cohort | mark | score |
|---|---|---|---|---|
| 1 | 101 | 2024 Intake | A | 4 |
| 1 | 102 | 2024 Intake | A | 4 |
| 1 | 105 | 2024 Intake | A | 4 |
Expected output
Your answer should return 2 rows with the columns apprentice_id.
Starter code (SQL)
SELECT *
FROM apprentices;Solve this SQL question free
Write SQL and run it instantly in your browser — even on your phone. No signup needed to try.
Solution & explanation
Create a free account to unlock the optimal solution, a step-by-step explanation, and the hidden test cases that grade your answer.
Sign up free to unlock