DB2通过某列分组来去重,可防止distinct对大字段的去重报错。
row_number() OVER (PARTITION BY COL1 ORDER BY COL2) 表示根据COL1分组,在分组内部根据 COL2排序,而此函数计算的值就表示每组内部排序后的顺序编号(组内连续的唯一的)
SELECT *, Row_Number() OVER (partition by deptid ORDER BY salary desc) as aa rank FROM employee WHERE aa = 1