February 13, 2020 at 8:50 am
Hi All,
I am looking for a way to add unique sequence number to my result set in sql server even though there is duplicates or not.
For Example, If first 3 rows are duplicate rows then the sequence should be 1 instead of 1,2,3. Then if the 4th,5th row is duplicate then sequence should be 2 instead of 4,5, If the 6th row is not duplicate then it should be 3 like that
Please find the attached image
February 13, 2020 at 9:00 am
You would want to look at the DENSE_RANK() window function for this, ordered by the customer name.
If you still struggle, let us know, with what you tried and we can point you in the right areas where it seems to be going wrong.
February 13, 2020 at 12:19 pm
I normally use ROWNUMBER() over (order by x partition by y) - usually because It involves finding the first order of the day for that product type (partition by product order by dateordered)
but any of the windowing functions could help - just make sure you understand the difference between rank, dense rank, row number
shout out if you need anything
MVDBA
February 14, 2020 at 6:43 pm
please check the article -
https://docs.microsoft.com/en-us/sql/t-sql/functions/dense-rank-transact-sql?view=sql-server-ver15
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply