Practice Free
HardBusiness Analytics High Frequency

Departmental Employee Tenure & Resignation Rates

Frequently Asked By:GoogleMetaMicrosoft
Interactive In-Browser Workspace

Practice this problem on live schema tables in PostgreSQL 16 WASM with instant row verification and visual EXPLAIN plans.

Solve in Workbench

Problem Statement

Group employees in `workforce_records` by `department`. Calculate: 1. `department` 2. `total_hires`: Total employee records in that department 3. `resigned_count`: Count of employees with `status = 'resigned'` 4. `turnover_rate_pct`: `ROUND(100.0 * COUNT(*) FILTER (WHERE status = 'resigned') / COUNT(*), 1)` Order results by `turnover_rate_pct` descending, then by `department` ascending.

Why Technical Interviewers Ask This

People analytics benchmarks department retention by measuring employee turnover rate (resigned staff divided by total headcount ever hired in that department).

Common Pitfalls & Interview Traps

Forgetting required sorting and deterministic tie-breaking.
Not accounting for NULL or zero-value denominators during calculations.
Using inefficient quadratic subqueries instead of single-pass business analytics constructs.

Canonical Modern SQL Solution

PostgreSQL 16 / ANSI SQL
SELECT 
        department,
        COUNT(*) AS total_hires,
        COUNT(*) FILTER (WHERE status = 'resigned') AS resigned_count,
        ROUND(100.0 * COUNT(*) FILTER (WHERE status = 'resigned') / COUNT(*), 1) AS turnover_rate_pct
      FROM workforce_records
      GROUP BY department
      ORDER BY turnover_rate_pct DESC, department ASC;
Approach Breakdown
This query addresses the problem requirements by filtering and structuring data in Business Analytics. It meets the target criteria: Departmental turnover rates and resignation counts.

Edge Cases to Verbally Clarify with Your Interviewer

The dataset contains zero matching records (must return valid empty result without crashing).
Multiple records tie on sorting criteria (must evaluate tie-breaking order deterministically).
Foreign keys or secondary attributes have NULL values.

Frequently Asked Follow-Up Questions

What makes this question a favorite among Google and Meta interviewers?

Interviewers use this problem to test whether candidates write defensive, scalable Business Analytics queries that run efficiently on multi-million row production databases without excessive memory usage.

How does the query optimizer execute this query?

Using single-pass table scans with index lookups or sort buffers. Running EXPLAIN (ANALYZE, BUFFERS) in the DB Exercises workbench visualizes the execution nodes and buffer hit cache.

More FAANG SQL Interview Questions

View all questions