SQL QuestSQL Interview Questions › Conditional Logic

Promotion Eligibility Matrix

MediumFreeQuerying BasicsConditional LogicDate Functions

Engineering ladder review. For each employee, assign a promotion-eligibility tag based on tenure (years from hire_date to 2024-06-01) and performance_rating. Branches in priority order:

1. 'Hold' — performance_rating < 3.5 (regardless of tenure — performance gates everything)
2. 'New Hire' — tenure_years < 1
3. 'Fast-Track' — performance_rating >= 4.5 AND tenure_years >= 2
4. 'Eligible' — performance_rating >= 4.0 AND tenure_years >= 3
5. 'On Track' — everyone else

Compute tenure_years as CAST((JULIANDAY('2024-06-01') - JULIANDAY(hire_date)) / 365 AS INTEGER). Show name, department, tenure_years, performance_rating, eligibility. Sort by performance_rating descending, then tenure_years descending.

Two traps stack here. First: branch order — 'New Hire' must come before 'Fast-Track' or new high performers wrongly get fast-tracked at 8 months. Second: SQL has no local variables, so the JULIANDAY tenure expression has to be repeated inside CASE (or wrapped in a subquery / CTE). Forgetting THEN after a long compound WHEN clause is the silent killer — you stare at the query and the parser just says "syntax error" with no clue where.

Solve it in the browser editor →

Runs on SQLite in your browser, graded against the expected result, no signup. A wrong answer gets a diagnosis, not just "incorrect".

Schema

employees

emp_idnamedepartmentpositionsalaryhire_datemanager_idperformance_rating
1Alice JohnsonEngineeringSenior Developer950002019-03-1554.5
2Bob SmithEngineeringDeveloper750002020-06-0113.8
3Carol WilliamsMarketingMarketing Manager850002018-09-20NULL4.2

Expected output: Bob → New Hire (tenure < 1 wins over Fast-Track)

Hint

Repeat the JULIANDAY tenure expression inside the CASE (or move both into a CTE). Branch order: Hold → New Hire → Fast-Track → Eligible → On Track. Every WHEN needs a THEN — the parser will not point at the missing one, it will point at whatever comes after.

Concepts

SELECT CASE Date Functions AND Date Functions + CASE

Practise the topic: SQL practice questions · CASE WHEN practice · Date function practice

Related questions

Movie Rating Tier BreakdownMedium · FreeGenre Financial ReportMedium · FreeDepartment Compensation ReportMedium · FreePivot: Order Status by CountryMedium · FreeGenre Box Office ReportMedium · FreeFare Imputation AnalysisMedium · Free

Where would this cost you points in an interview?

Ten questions, no signup: a Skillmap across nine SQL skills and the one to fix first.

Take the readiness test