Just wanna ask, is it possible to update the result of a derived table.
My code is below:
UPDATE FROM (select a.*, row_number() over
(partition by device_util_id
order by service_point_util_id, install_date desc) as rownum
from eadwstage.test_device_locations a) tst
set DELTA_FLAG = 'D'
where tst.rownum <> 1
My query is throwing invalid SQL statement.
I also tried adding the DeviceID in WHERE condition but it updated both IDs into 'D'
Sample data are:
+----------+-------------+---------------+------------+
| DeviceID | Location | DELTA_FLAG | ROWNUM |
+----------+-------------+---------------+------------+
| 1 | US | I| 1 |
| 1 | UK | U| 2 |
| 2 | MY | I| 1 |
| 3 | JP | I| 1 |
+----------+-------------+---------------+------------+
Basically, I wanted to update the records that have rownum > 1 to 'D' Delta_Flag.
Below is how I wanted:
+----------+-------------+---------------+------------+
| DeviceID | Location | DELTA_FLAG | ROWNUM |
+----------+-------------+---------------+------------+
| 1 | US | I| 1 |
| 1 | UK | D| 2 |
| 2 | MY | I| 1 |
| 3 | JP | I| 1 |
+----------+-------------+---------------+------------+
*Note: the ROWNUM column is not part of the table
Databse is either Oracle or Teradata