Coalesce null salaries to zero
SQL data engineering interview problem. Difficulty: beginner. Pattern: Missing Data. About 8 minutes. Free to practice.
A report is going to a manager who gets confused by empty cells. Some employees have no salary on file (NULL), and the report should show 0 for them instead of leaving the cell blank. Return every employee's name and salary. When the salary is NULL, show 0. Sort by name from A to Z.
Requirements
- Return every employee, with no rows removed.
- Replace a NULL salary with 0 using COALESCE.
- The column must still be called salary, so give the COALESCE result that name with AS.
- Sort by name from A to Z.
Constraints
- The table is employees.
- Return only these 2 columns, in this order: name, salary.
- Each employee appears exactly once.
Examples
Input: employees name | salary Alice Chen | 120000 Max Reed | NULL Omar Ali | 105000 Output: name | salary Alice Chen | 120000 Max Reed | 0 Omar Ali | 105000 Why this passes: COALESCE replaces NULL with 0 without dropping the row.
Topics: lakebench, sql, coalesce, null.
More SQL interview questions · All interview problems · Learn data engineering
Coalesce null salaries to zero
Interview-style drill: Return each employee name with salary defaulted to 0 when NULL.
For every employee, return `name` and `salary` where NULL salary becomes 0 via COALESCE. Order by `name`.