ROW NUMBER() OVER

前端 未结 2 1520
迷失自我
迷失自我 2021-01-17 17:27

I came across a somewhat special syntax, could you help in figuring out what it means? Thank you.

SELECT ROW NUMBER() OVER (ORDER BY Product.ProductID) FROM          


        
相关标签:
2条回答
  • 2021-01-17 17:40

    The ROW_NUMBER() function requires the OVER(ORDER BY) expression to determine the order that the rows are numbered. The default order is ascending but descending can also be used. This function is useful for a variety of things like keeping track of rows when iterating through a set of records since T-SQL does not allow a cursor to be retrieved outside of T-SQL. @tunimise fasipe is correct, you are missing the _

    0 讨论(0)
  • 2021-01-17 17:41

    Note that your are missing the underscore in ROW_NUMBER

    SELECT ROW_NUMBER() OVER (ORDER BY Products.ProductID) FROM Products;
    

    What it does is that it prints out the row number of each record in the products table in the order they were retrieved (as ordered by ProductID)

    e.g.
    RowNumber   ProductName
    ------------------------
    1           Flower
    2           Bag
    3           Car
    ...         ...
    

    I added the ProductName column for clarity

    0 讨论(0)
提交回复
热议问题