Business requirements:
After the current work order is executed, it will be transferred to the next work order for operation, and the work order table data will be sorted in a series, and the work order operation will be executed in order.
ROW_NUMBER() OVER function:
Row_number() starts from 1 and returns a number for each grouped record. When using the row_number() over() function, the execution of grouping and sorting in over() is later than where group by order by.
partition by is used to group the result set. If it is not specified, it takes the whole result set as a group. It is different from the aggregation function in that it can return multiple records in a group, while the aggregation function generally has only one record reflecting the statistical value.
Raise a chestnut.
select Date date,OrderID Work order number,OrderSeq Order of work order,Row_Number() over(order by OrderSeq) as Actual order from ( select 'order001' as OrderID,'2018-2-3' as Date, 10 as OrderSeq union all select 'order002' as OrderID,'2018-2-3' as Date, 20 as OrderSeq union all select 'order003' as OrderID,'2018-2-5' as Date, 30 as OrderSeq union all select 'order004' as OrderID,'2018-2-4' as Date, 10 as OrderSeq union all select 'order005' as OrderID,'2018-2-4' as Date, 20 as OrderSeq ) aa
The "actual order" column is the column generated by the function, which is sorted according to the "work order order"
Similar functions
Result:select Date date,OrderID Work order number,OrderSeq Order of work order,Rank() over(order by OrderSeq) as Actual order from ( select 'order001' as OrderID,'2018-2-3' as Date, 10 as OrderSeq union all select 'order002' as OrderID,'2018-2-3' as Date, 20 as OrderSeq union all select 'order003' as OrderID,'2018-2-5' as Date, 30 as OrderSeq union all select 'order004' as OrderID,'2018-2-4' as Date, 10 as OrderSeq union all select 'order005' as OrderID,'2018-2-4' as Date, 20 as OrderSeq ) aa

Result:select Date date,OrderID Work order number,OrderSeq Order of work order,dense_rank() over(order by OrderSeq) as Actual order from ( select 'order001' as OrderID,'2018-2-3' as Date, 10 as OrderSeq union all select 'order002' as OrderID,'2018-2-3' as Date, 20 as OrderSeq union all select 'order003' as OrderID,'2018-2-5' as Date, 30 as OrderSeq union all select 'order004' as OrderID,'2018-2-4' as Date, 10 as OrderSeq union all select 'order005' as OrderID,'2018-2-4' as Date, 20 as OrderSeq ) aa
