SQL Quest › SQL 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". Free accounts get 10 free challenge solves, and this can be one of them.

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

Read the concept: SQL running total

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

January 2024 OrdersEasy · FreePre-1900 BanksEasy · Free2025 SalesEasy · FreeQuarterly Hiring Cohort ReportMedium · FreeMonthly Order TrendsMedium · FreeDate Functions: How Long Ago?Medium · 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