Forward-Fill NULL Job Roles
Problem
**[Classic — asked at multiple analytics companies]**
An employee log records role changes; NULL means no change that period.
Fill each NULL `job_role` with the **most recent non-NULL role** for that employee.
Return `employee_id`, `log_date`, and `filled_role`, ordered by employee then date.
Tables
Example rows — the live problem includes the full dataset.
employee_log
| log_id | employee_id | log_date | job_role |
|---|
Expected output
Your answer should return 7 rows with the columns employee_id, log_date, filled_role.
Starter code (SQL)
SELECT *
FROM employee_log;Solve this SQL question free
Write SQL and run it instantly in your browser — even on your phone. No signup needed to try.
Solution & explanation
Create a free account to unlock the optimal solution, a step-by-step explanation, and the hidden test cases that grade your answer.
Sign up free to unlock