I have a table called employees, with 'employee_id'
and 'bonuses'
as columns. The employee_id's are repeated because they have multiple bonuses of different amounts, and I want to rank them by their total bonus amount.
So, I was wondering if this would be the correct way to rank the employees by their total bonus amount descending:
SELECT employee_id, SUM(bonuses) AS total_bonus, DENSE_RANK(ORDER BY total_bonus DESC) AS bonus_rank
FROM employees
GROUP BY employee_id;
My desired output is a table with the employee_id
only listed once, the corresponding total bonus amount the employee received
, and the rank of bonuses starting from rank #1 with the highest total bonus amount
.