1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

[SQL] Creating groups for a specific set of rows

Discussão em 'Outras Linguagens' iniciado por Stack, Outubro 15, 2024 às 08:12.

  1. Stack

    Stack Membro Participativo

    I have this table

    ProductID Price ID
    90271 569 1
    90271 455 2
    90271 669 3
    90271 535 4
    90271 535 5
    90271 535 6
    90271 419 7
    90271 300 8
    90271 419 9
    90271 419 10
    90271 535 11

    I need to add a GroupID column that groups the same prices under one GroupID before the next row changes the price. I can't simply use Dense_Rank() , because it creates the same GroupID for rows with ID 4,5,6,11.

    Can you please advise me how to solve this?

    ProductID Price ID GroupID
    90271 569 1 1
    90271 455 2 2
    90271 669 3 3
    90271 535 4 4
    90271 535 5 4
    90271 535 6 4
    90271 419 7 5
    90271 300 8 6
    90271 419 9 7
    90271 419 10 7
    90271 535 11 8

    Continue reading...

Compartilhe esta Página