圣誕節快樂,
我正在使用以下查詢來獲取價格,但我的要求是從 trunc(sysdate) 獲取過去一年的資料。我曾嘗試使用 DATEADD 函式,但它給了我一個錯誤
cast(p.asof as DATE) = cast(DATEADD(Year, -1, GETDATE()) as DATE)
select idvalue, p.asof as DATE_, p.instrument, p.price
from instruments i
inner join prices_equity_closing p on p.instrument = i.pkey
inner join instruments_ids id on i.ids = id.idset
where
id.idvalue in ('MRVE3.SA')
and id.idtype in ('RIC')
and p.asof = trunc(sysdate)-1
order by i.exchange, i.type, p.asof desc;
任何人都可以幫忙,我需要進行哪些更改才能獲得所需的結果?
uj5u.com熱心網友回復:
使用 add_months 和 sysdate:
select add_months(sysdate,-12) x from dual
uj5u.com熱心網友回復:
您可以從當前日期減去 12 個月的 INTERVAL。
...
where
id.idvalue in ('MRVE3.SA')
and id.idtype in ('RIC')
and p.asof >= trunc(sysdate) - interval '12' month
order by i.exchange, i.type, p.asof desc;
uj5u.com熱心網友回復:
或者我們可以簡單地使用和 p.asof > trunc(sysdate)-365
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/392768.html
