SQL QuestSQL Interview Questions › Date Functions

Employee Tenure Bands

MediumFreeQuerying BasicsDate FunctionsConditional LogicSubqueries & CTEsAggregation & Grouping

Classify employees into tenure bands based on years at the company (relative to 2024-06-01): 'Veteran' (8+ years), 'Experienced' (4–7), 'Mid-level' (2–3), 'Junior' (< 2 years). For each band show band, employee_count, and avg_salary (rounded to nearest dollar). Sort by avg_salary descending.

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: 4 tenure bands with headcount and salary benchmarks

Hint

Use a CTE to compute tenure years first: CAST((julianday('2024-06-01') - julianday(hire_date)) / 365 AS INTEGER). Then CASE on that value in the outer query

Concepts

SELECT Date Functions CASE CTE GROUP BY Aggregation Date Functions + CASE

Practise the topic: SQL practice questions · Date function practice · CASE WHEN practice · CTE practice · GROUP BY exercises

In these company practice sets

Tesla

A SQL Quest challenge matched to patterns reported for these companies — not a question any of them has published.

Related questions

Quarterly Hiring Cohort ReportMedium · FreeCustomer Recency AnalysisMedium · FreeMonthly Order TrendsMedium · FreeDate Functions: How Long Ago?Medium · FreeMonthly Order Volume in 2024Medium · FreeMulti-Month Active CustomersMedium · 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