Detect outliers using percentile
SQL
Hard
4 views
Problem Description
Find employees whose salary is above the 90th percentile in their department.
Sample Test Case
Input:
Employees(dept_id, salary)
Constraints
Use percentile function if supported
Official Solution
SELECT emp_id, dept_id, salary FROM (SELECT emp_id, dept_id, salary, PERCENT_RANK() OVER (PARTITION BY dept_id ORDER BY salary) AS pr FROM Employees) t WHERE pr >= 0.90;
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!