yahoo2344
yahoo2344

Reputation: 107

I'd like to check the column and specify row_number()

 name          type    grade       site                   date         num
  Toy           c        A       test.com               20210315        1
  Toy           c        B       test.com               20210315        2
  Toy           a        B       test.com               20210315        1
  Tool          a        A       gonggu.com             20210315        1
  Tool          a        c       gonggu.com             20210315        2
  Electronics   b        A       electro.com            20210315        1
  Electronics   b        B       electro.com            20210315        2

The result should be like that, but I don't know how to write a query.

Upvotes: 0

Views: 34

Answers (1)

Tim Biegeleisen
Tim Biegeleisen

Reputation: 522441

I believe you want to use ROW_NUMBER as follows:

SELECT *, ROW_NUMBER() OVER (PARTITION BY name, type, site ORDER BY grade) num
FROM yourTable;

Upvotes: 1

Related Questions