网站首页 美食营养 游戏数码 手工爱好 生活家居 健康养生 运动户外 职场理财 情感交际 母婴教育 时尚美容

ROW_NUMBER() OVER函数的基本用法

时间:2024-10-13 01:00:23

1、简单的说row_number()从1开始,为每一条分组记录返回一个数字,这里的ROW_NUMBER() OVER (ORDER BY xlh DESC) 是先把xlh列降序,再为降序以后的没条xlh记录返回一个序号。

ROW_NUMBER() OVER函数的基本用法

2、row_number() OVER (PARTITION BY COL1 ORDER BY COL2)表示根据COL1分组,在分组内部根据 COL2排序,而此函数计算的值就表示每组内部排序后的顺序编号(组内连续的唯一的)

3、实例:初始化数据create table employee (empid int ,deptid int ,salary decimal(10,2))insert into employee values(1,10,5500.00)insert into employee values(2,10,4500.00)insert into employee values(3,20,1900.00)insert into employee values(4,20,4800.00)insert into employee values(5,40,6500.00)insert into employee values(6,40,14500.00)insert into employee values(7,40,44500.00)insert into employee values(8,50,6500.00)insert into employee values(9,50,7500.00)数据显示为

ROW_NUMBER() OVER函数的基本用法

4、需求:根据部门分组,显示每个部门的工资等级预期结果:

ROW_NUMBER() OVER函数的基本用法

5、SQL脚本:SELECT *, Row_Number() OVER (partition by deptid ORDER BY salary desc) rank FROM employee

© 2025 一点资料
信息来自网络 所有数据仅供参考
有疑问请联系站长 site.kefu@gmail.com