AnalystPath

Distinction Apprentices

SQLHardSenior level~15 min

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.

apprentices
apprentice_idfull_nametrade
1NadiaPlumbing
2OmarPlumbing
3PriyaWelding
units
unit_idtitleweekstradecore
101Pipe Fitting3PlumbingYes
102Drainage3PlumbingYes
103Arc Basics4WeldingYes
records
apprentice_idunit_idcohortmarkscore
11012024 IntakeA4
11022024 IntakeA4
11052024 IntakeA4

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

Related SQL questions