- I am updating PREVIOUS_DAY_CLOSE column which contains DAY_CLOSE-1 values.
- I am using LAG() function to get PREVIOUS_DAY_CLOSE values. Its working fine.
- But updating the column with UPDATE and SELECT statement which is showing errors.
DAY | DAY_OPEN | DAY_CLOSE | PREVIOUS_DAY_CLOSE |
---|---|---|---|
29-05-2024 | 16879.35 | 16920.58 | |
28-05-2024 | 16988.31 | 17019.88 | |
24-05-2024 | 16879.35 | 16920.79 | |
23-05-2024 | 16996.39 | 16736.03 |
I have tried below queries and facing errors.
ORA-00928: missing SELECT keyword
with t1 as
(
SELECT datetime, LAG(CLOSE) OVER (ORDER BY datetime)AS PREVIOUS_CLOSE
from stocks where SYMBOL='NASDAQ:IXIC'
)
update STOCKS
set PREVIOUS_CLOSE=t1.PREVIOUS_CLOSE
from t1
where t1.datetime=STOCKS.datetime;
SQL Error: ORA-01427: single-row subquery returns more than one row
update STOCKS
set PREVIOUS_CLOSE=
(SELECT LAG(CLOSE) OVER (ORDER BY datetime)AS PREVIOUS_CLOSE from STOCKS where SYMBOL='NASDAQ:IXIC')
;