I have data in this format:
ID| DATE
--------
1 | 02/23/2014
1 | 05/15/2011
1 | 01/05/2017
2 | 12/21/2013
3 | 10/10/2016
3 | 09/05/2015
For Each ID Group I want to update the dates starting from yesterday onward(decreasing order). Considering todays date is 09/28/2017, Output should be like:
ID | DATE
--------
1 | 09/27/2017
1 | 09/26/2017
1 | 09/25/2017
2 | 09/27/2017
3 | 09/27/2016
3 | 09/26/2017
My approach was (which is not working)
UPDATE TABLE
SET DATE = CURRENT DATE - p.a days
FROM (
SELECT DATE
,ID
,ROW_NUMBER() OVER (
PARTITION BY ID ORDER BY ID ASC
) a
FROM TABLE
) p
WHERE DATE = p.DATE
AND ID = p.ID
WITH ur;
Kindly suggest any method to achieve the same.
Edit:
Database : DB2
Error :
ERROR [42601] [IBM][DB2/AIX64] SQL0104N An unexpected token "from" was found following "rent date - p.a days". Expected tokens may include: "".
Date Column Data type: Date
'DATE'? If those are the only two columns you have, though, the ordering is irrelevant (since the data is overwritten). - Clockwork-Muse