#64
Second Largest Salary
EASYAggregation & SubqueryPOSTGRESQL
Problem Description
Payroll analytics pipelines commonly query compensation tables to set salary band thresholds and flag outlier pay structures. A typical step in such pipelines is identifying the second-highest distinct salary — used by HR systems to define the upper boundary of the second salary band and to detect when a single outlier is distorting the entire pay distribution.
Your task is to find the second largest distinct salary from the `employees` table. If there is no second largest salary (only one distinct salary value exists, or the table is empty), return `NULL`.
Topics
ranking
Asked at Companies
salesforce
Solve This Problem
Sign up to access the interactive code editor, run test cases, view the editorial, and get AI-powered feedback on your solution.
Start Solving →