ROW NUMBER() OVER

前端 未结 2 1556
迷失自我
迷失自我 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: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

提交回复
热议问题