こんにちは、私は難しい問題に直面しています:
私は天気予報のテーブル (オラクル 9i) を持っています (サイズは何億ものレコードです)。その構成は次のようになります。
stationid forecastdate forecastinterval forecastcreated forecastvalue
---------------------------------------------------------------------------------
varchar (pk) datetime (pk) integer (pk) datetime (pk) integer
どこ:
stationid
予報を作成する可能性のある多くの気象観測所の 1 つを指します。forecastdate
予測対象の日付を指します (時刻ではなく日付のみ)。forecastinterval
forecastdate
予測の時間 (0 ~ 23) を参照します。forecastcreated
予測が行われた時間を指し、何日も前になる可能性があります。forecastvalue
予測の実際の値を参照します (名前が示すように)。
stationid
与えられたものと与えられたものforecastdate
とのペアについて、公称数(500など)よりも大きく増加forecastinterval
するレコードを決定する必要があります。forecastvalue
ここに条件の表を示します。
stationid forecastdate forecastinterval forecastcreated forecastvalue
---------------------------------------------------------------------------------
'stationa' 13-dec-09 10 10-dec-09 04:50:10 0
'stationa' 13-dec-09 10 10-dec-09 17:06:13 0
'stationa' 13-dec-09 10 12-dec-09 05:20:50 300
'stationa' 13-dec-09 10 13-dec-09 09:20:50 300
上記のシナリオで、3 番目のレコードを取り出したいと思います。これは、予測値が公称 (100 など) だけ増加したレコードです。
テーブルのサイズが非常に大きく (何億ものレコード)、完了するまでに非常に長い時間がかかる (実際、クエリが返されないほど長い) ため、タスクは非常に困難であることが判明しています。
これらの値を取得するためのこれまでの私の試みは次のとおりです。
select
wtr.stationid,
wtr.forecastcreated,
wtr.forecastvalue,
(wtr.forecastdate + wtr.forecastinterval / 24) fcst_date
from
(select inner.*
rank() over (partition by stationid,
(inner.forecastdate + inner.forecastinterval),
inner.forecastcreated
order by stationid,
(inner.forecastdate + inner.forecastinterval) asc,
inner.forecastcreated asc
) rk
from weathertable inner) wtr
where
wtr.forecastvalue - 100 > (
select lastvalue
from (select y.*,
rank() over (partition by stationid,
(forecastdate + forecastinterval),
forecastcreated
order by stationid,
(forecastdate + forecastinterval) asc,
forecastcreated asc) rk
from weathertable y
) z
where z.stationid = wtr.stationid
and z.forecastdate = wtr.forecastdate
and (z.forecastinterval =
wtr.forecastinterval)
/* here is where i try to get the 'previous' forecast value.*/
and wtr.rk = z.rk + 1)