在示例数据集中,部门是唯一的,因此您可以:
PARTITION BY department
但是,如果多个公司可以拥有同一部门,则需要:
PARTITION BY company, department
旁注:由于您要对company, department, employee
第三个over
子句进行分组是多余的。您可以通过省略它来简化:
ORDER BY SUM(SUM(sales)) over (PARTITION BY company) DESC , SUM(SUM(sales)) over (PARTITION BY company, department) DESC , SUM(sales) DESC