我有一个名为employees 的表,带有'employee_id'
和'bonuses'
作为列。重复employee_id是因为它们有多个不同金额的奖金,我想按奖金总额对它们进行排名。
所以,我想知道这是否是按员工总奖金金额降序排列的正确方法:
SELECT employee_id, SUM(bonuses) AS total_bonus, DENSE_RANK(ORDER BY total_bonus DESC) AS bonus_rank
FROM employees
GROUP BY employee_id;
我想要的输出是一个表,其中employee_id
仅列出一次、对应total bonus amount the employee received
的 和rank of bonuses starting from rank #1 with the highest total bonus amount
.