我被困在我的卡片/Oracle query上。
对这个问题,感兴趣的领域为:、_day
(td.ws_date)、ot.valid_from
和ot.valid_to.
。
There is one record returned for each effective_day
. The record is valid as long as it was edited on or before the effective_day
and on or after the effective_day
.
To find out when it was valid we look at the fieldsot.valid_from
and ot.valid_to.
ot.valid_from <= effective_day <= ot.valid_to
缩略语 可在一天多时间更新valid_to
andvalid_from
。 相应更新这些领域。 因此,在三天的时间里,一项命令的更新可能希望:
ID |Order | Valid From | Valid To |
=================================================================
0 |112 | 07-SEP-11 21:13:12 | 08-SEP-11 01:02:11 |
1 |112 | 08-SEP-11 01:02:12 | 08-SEP-11 01:14:12 |
2 |112 | 08-SEP-11 01:14:13 | 09-SEP-11 05:23:51 |
3 |112 | 09-SEP-11 05:23:52 | 09-SEP-11 16:21:13 |
4 |112 | 09-SEP-11 16:21:14 | null |
If I want to return the order detals for effective_day = 08-SEP-11
. The data returned should be the most recently updated data for that day. So it should be ID 2.
Similarly, if I want to return the order details for effective_day = 09-SEP-11
then ID 4 should be returned.
这里,我
SELECT
td.ws_date effective_date,
ot.ORDER_NO,
ot.PROCESS_AREA,
ot.VALID_FROM,
ot.VALID_UNTIL
FROM ws_tracker_dates_tab td, ws_tracker_old_tab ot
WHERE (ot.VALID_FROM <= td.WS_DATE)
AND (ot.VALID_UNTIL IS NULL or (ot.VALID_UNTIL>=td.ws_date))
AND ot.COMPLETED = N
AND td.WS_DATE BETWEEN (SYSDATE -30) AND (SYSDATE)
AND ot.process_area is not null
Any help would be appreciated.