how to add flag sequence number in unique and duplicate value using sql

how to add flag sequence number in unique and duplicate value using sql

Problem Description:

i have table A with 2 columns was filled: Date, product. and column count still empty

my expectation, if same product have in same date then count 1.

i want the flag in count as sequence.
enter image description here

i got stuck, thanks before

Solution – 1

You may use DENSE_RANK() here:

SELECT date, product, DENSE_RANK() OVER (ORDER BY date, product) count
FROM yourTable
ORDER BY date, product;
Rate this post
We use cookies in order to give you the best possible experience on our website. By continuing to use this site, you agree to our use of cookies.
Accept
Reject