简体   繁体   English

分区上的Rownumber

[英]Rownumber over partition

Each employeeID has different network and customer.SoI want to have row number partitioned by network and Customer per EmployeeID. 每个employeeID都有不同的网络和客户。所以我希望网络分区的行号和每个EmployeeID的客户。

I tried the below code but it still gives same rownumber for an employee even if network and customer are different. 我尝试了以下代码,但即使网络和客户不同,它仍然为员工提供相同的rownumber。

select distinct ROW_NUMBER() OVER(PARTITION BY Network,CU,EmployeeiD ORDER BY Network,CU,EmployeeID)

I want 1,2,3 row numbers for an employee1 if he has 3 networks and also 1,2,3,4 for employee2 if he has 4 networks. 如果employee1有3个网络,我想要1,2,3行号,如果他有4个网络,我需要1,2,3,4作为employee2。

Can some one point me in right direction. 有人可以指出我正确的方向。

Thanks 谢谢

it still gives same rownumber for an employee even if network and customer are different 即使网络和客户不同,它仍然为员工提供相同的rownumber

Because you are partitioning by network and customer as well. 因为您也是按网络和客户进行分区。 I think you want: 我想你想要:

SELECT ROW_NUMBER() OVER(PARTITION BY EmployeeiD ORDER BY Network,CU)

That will give you the relative order of each record for each EmployeeID ordered (ascending) by Network first, then CU . 这将为您提供Network优先排序(升序)的每个EmployeeID的每条记录的相对顺序,然后是CU

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM