Question : subquery to update selected rows in table

create subquery to update selected rows in table
table is db2
requirements:
find the row with max timestamp, this is the considered the good row to get the values of the rgn & ovd
then, for all the rows in the table where the rgn is not = value of rgn good row, update these rows

sample of table & requirements in attached file

Answer : subquery to update selected rows in table

How about this?
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
UPDATE acr b
SET (b.rgn, b.ovrd, b.opr, b.dte, b.TIMESTAMP) =
 (SELECT DISTINCT rgn, ovrd, 'BTCHREQ', DECIMAL(REPLACE(CHAR(CURRENT dATE, ISO), '-', ''),8,0), CURRENT_TIMESTAMP
    FROM acr
    WHERE agt = b.agt
      AND timestamp = (SELECT MAX(timestamp) FROM acr WHERE agt = b.agt))
WHERE b.rgn <>
 (SELECT DISTINCT rgn
    FROM acr
    WHERE agt = b.agt
      AND timestamp = (SELECT MAX(timestamp) FROM acr WHERE agt = b.agt));
Random Solutions  
 
programming4us programming4us