Click here to Skip to main content
15,885,767 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
https://hosting.photobucket.com/images/i/lamvn74/Row_number_Picture.jpg?width=285&height=175&fit=bounds&crop=fill[^]

Please Help me !!!

Details from picture:
Table:
Row_Number1 | Row_Number2 | GroupJobID | JobID
----------------------------------------------
1           | 1           | 6200       | A001
1           | 2           | 6200       | A002
2           | 1           | 6202       | A003
2           | 2           | 6202       | A004
2           | 3           | 6202       | A005
3           | 1           | 6201       | A006
3           | 2           | 6201       | A007
3           | 3           | 6201       | A008
3           | 4           | 6201       | A009
4           | 1           | 6202       | A010
5           | 1           | 6201       | A011
How to write query Row_Number1 according to JobGroupID when JobGroupID changed.

What I have tried:

SQL
SELECT
    ROW_NUMBER() OVER (PARTITION BY JobGroupID ORDER BY JobGroupID) As RowNumber2,
    JobGroupID,
    JobID
FROM
    ABC
ORDER BY
    ABC.Orders ASC
Posted
Updated 15-Oct-20 22:50pm
v2
Comments
Richard Deeming 16-Oct-20 4:05am    
If you want to ask a question, then ask a question. Do not put your question in a picture on an external site!

1 solution

You requirement is not quite clear...

Try this:
SQL
SELECT RowNumber1, GroupJobID, JobID, ROW_NUMBER() OVER(PARTITION BY RowNumber1, GroupJobID ORDER BY JobID) RowNumber2
FROM Jobs


db<>fiddle[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900