ow_number() over (partition by EmployeeName order by empId)
这表示根据EmployeeName分组 然后再在每个EmployeeName内部进行排序标号,我一般把这叫做分组内部排序标号,而group by一般是与汇总函数合用,会对原数据进行汇总,这样的结果会使数据行数变少,
举个简单的例子
cl1 cl2
a 1
a 2
a 3
a 3
b 1
b 1
select cl1,sum(cl2) su from table1 group by cl1;
cl1 su
a 9
b 2
select cl1,cl2,sum(cl2) over(partition by cl1) su from table1 group by cl1;
cl1 cl2 su
a 1 9
a 2 9
a 3 9
a 3 9
b 1 2
b 1 2
select cl1,cl2,row_number() over(partition by cl1 order by cl2) row_num from table1 group by cl1;
cl1 cl2 row_num
a 1 1
a 2 2
a 3 3
a 3 4
b 1 1
b 1 2
这个例子能够说明了吧,你可以百度group by与partition by的区别,上述为我自己学习的想法,如有错误请见谅
x只是一个别名吧,就是代替你的查询
(
select *, rn=row_number() over (partition by EmployeeName order by empId)
from Employee
)的内容,