Given a table
CREATE TABLE TABLE_ITEMS (
serial_num int null,
item_group int null
);
INSERT INTO TABLE_ITEMS
VALUES
(0,1), (1,1), (2,1), (3,1), (4,1),
(0,2), (1,2), (2,2), (3,2), (4,2), (5,2),
(0,3), (1,3), (2,3);
and so on…
I need to know how to run a query which will update the rows with 0
as the serial_num
to be the next number in the serial_num
sequence for the given item_group
The result will look like this:
those were the zeroes
↓
(**5**,1) (1,1) (2,1) (3,1) (4,1)
(**6**,2) (1,2) (2,2) (3,2) (4,2) (5,2)
(**3**,3) (1,3) (2,3)
I want to update an item in serial_num=0
to be the last serial_num
plus 1 (if the last one was 70, it needs to be 71).
How can I do it?
Best Answer