简体   繁体   中英

Rownumber over partition

Each employeeID has different network and customer.SoI want to have row number partitioned by network and Customer per EmployeeID.

I tried the below code but it still gives same rownumber for an employee even if network and customer are different.

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.

Can some one point me in right direction.

Thanks

it still gives same rownumber for an employee even if network and customer are different

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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