在Oracle數(shù)據(jù)庫中,rank()和row_number()都是用于對查詢結(jié)果進(jìn)行排序的窗口函數(shù),但它們有一些區(qū)別。
示例:
SELECT emp_name, salary,
RANK() OVER (ORDER BY salary DESC) AS salary_rank
FROM employees;
示例:
SELECT emp_name, salary,
ROW_NUMBER() OVER (ORDER BY salary DESC) AS row_num
FROM employees;
總的來說,rank()函數(shù)會出現(xiàn)相同排名,而row_number()函數(shù)會給每一行都分配唯一的行號。根據(jù)具體需求選擇合適的函數(shù)。