I want to increase the sequence number for the subgroups inside the table, but if the subgroup does not exist, the sequence should start with 1:
For example, in the following, we want the sequence to be set to 1 if there are no entries in the table with class=5; if there is such a record, then the sequence should take the value max sequence (in the subgroup class=5) + 1:
update order set class=5, sequence=(select max(sequence) from order
where class=5)+1 where order_id=104;
The problem is that this does not work for the initial case.
source
share