Search code examples
sqlrow-numberdbeaver

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


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

  • You may use DENSE_RANK() here:

    SELECT date, product, DENSE_RANK() OVER (ORDER BY date, product) count
    FROM yourTable
    ORDER BY date, product;