SQL data engineering interview problem. Difficulty: advanced. Pattern: Self Joins. About 18 minutes. Part of the Pro drill bank.
Find pairs of employees in the same non-null department whose absolute salary difference is < 5000. Return employee_1, employee_2 (names), department, salary_diff (absolute difference). Include each unordered pair once (employee_1 < employee_2 by name). Exclude NULL salaries. Order by department, employee_1, employee_2.
Input: employees (Engineering) name | department | salary Bob Kumar | Engineering | 95000 Eve Ng | Engineering | 95000 Dan Park | Engineering | 110000 Output: employee_1 | employee_2 | department | salary_diff Bob Kumar | Eve Ng | Engineering | 0 Why this passes: Dan differs by 15000 from Bob, so that pair is excluded by the < 5000 rule.
Topics: lakebench, sql, self-join, pairs.
More SQL interview questions · All interview problems · Learn data engineering
Interview-style drill: Pairs in the same department with salary difference under 5000.
Find pairs of employees in the same non-null department whose absolute salary difference is < 5000. Return `employee_1`, `employee_2` (names), `department`, `salary_diff` (absolute difference). Include each unordered pair once (`employee_1` < `employee_2` by name). Exclude NULL salaries. Order by `department`, `employee_1`, `employee_2`.