Rank current salaries
hardRank employees by current salary from highest to lowest. Return employee id, salary, and rank; sort by rank then employee id.
Hospital Database · SQLite
Run your SQL answer to see the returned rows and check it.
SELECT e.employee_id, s.salary, RANK() OVER (ORDER BY s.salary DESC) AS salary_rank FROM employees AS e JOIN salaries AS s ON s.employee_id = e.employee_id WHERE s.to_date IS NULL ORDER BY salary_rank, e.employee_id;