如何在SQL表的开头添加行号列?

时间:2018-10-28 07:36:38

标签: sql select row-number

select 
    CodeColumn, NameColumn, UnitCostColumn, DiscountRateColumn,
    TotalColumn, DescriptionColumn,
    row_number() over (order by CodeColumn) AS RowNumber
from 
    GoodsTable1

这是我使用的代码。但是它在表的末尾添加了RowNumber。我不要那个

1 个答案:

答案 0 :(得分:1)

只需将“列”移动到选择列表的开头:

SELECT ROW_NUMBER() OVER (ORDER BY CodeColumn) AS RowNumber, -- Here!
       CodeColumn,
       NameColumn,
       UnitCostColumn,
       DiscountRateColumn,
       TotalColumn,
       DescriptionColumn
FROM   GoodsTable1