How do I use ROW_NUMBER()?

前端 未结 13 2428
青春惊慌失措
青春惊慌失措 2020-11-28 02:35

I want to use the ROW_NUMBER() to get...

  1. To get the max(ROW_NUMBER()) --> Or i guess this would also be the count of all rows
13条回答
  •  死守一世寂寞
    2020-11-28 03:09

    Need to create virtual table by using WITH table AS, which is mention in given Query.

    By using this virtual table, you can perform CRUD operation w.r.t row_number.

    QUERY:

    WITH table AS
    -
    (SELECT row_number() OVER(ORDER BY UserId) rn, * FROM Users)
    -
    SELECT * FROM table WHERE UserName='Joe'
    -
    

    You can use INSERT, UPDATE or DELETE in last sentence by in spite of SELECT.

提交回复
热议问题