简体   繁体   中英

I want to update a table to number the positions of orders

I have a legacy table with orders and their (sometimes multiple) rows with varchar values:

Order       Row
1           1
1           1a
1           1b
2           1
2           2

I want to introduce another integer field "ROW_NR"

Order       Row      ROW_NR
1           1         1
1           1a        2
1           1b        3
2           1         1
2           2         2

which will hold the number of the row in the resp. order.

How can I accomplish updating the new field using SQL?

Window-Functions can be used to achive this, like described in Firebird windowing

(using keywords as column-name is very bad practice, in example replaced by _order_ and _row_)


ROW_NUMBER () OVER (PARTITION BY _order_ order by _row_ asc) as row_num

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM