0

Oracle 9i を SQL 開発者と一緒に使用する

表2に日付がない場合、最新の日付のレート値を使用する方法を教えてもらえますか.現在、6月4日のレートがないため、木曜日のレートを使用するように6月4日(月曜日)をハードコードしています. 週末は簡単な部分でした。しかし、休日の日付を手動でハードコーディングすることなく、これを行いたいと考えています。誰か助けてくれませんか?

select 
m.effective_date, 
m.value*al.rate

from table1 m, table2 al
where  
M.ID = al.ID 
AND M.EFFECTIVE_DATE BETWEEN '01-jun-12' and '30-jun-12'
and AL.value_date = m.EFFECTIVE_date -     ( case     
when m.EFFECTIVE_date = '04-jun-12' then 3
when to_char(m.EFFECTIVE_date,'DY') = 'SUN' then 2  
when to_char(m.EFFECTIVE_date,'DY') = 'SAT' then 1  
ELSE 0  
end ) 

table1 

Effective_date         Value
06-01-2012            100
06-02-2012            200
06-03-2012            600
06-04-2012           600
 All the way to 06-30-2012  



Table 2 (does not have weekends and some dates depending on UK holiday)

Value_date           Rate
06-01-2012           1.2
06-05-2012            1.5
06-06-2012            5.3
06-07-2012            1.5
06-08-2012            5.6
06-11-2012            1.5
06-12-2012             1.9
06-13-2012             2.1
4

1 に答える 1

0

これを試して:

SELECT m.effective_date, 
m.value*al.rate
from table1 m, table2 al
where  
M.ID = al.ID 
AND M.EFFECTIVE_DATE BETWEEN '01-jun-12' and '30-jun-12'
WHERE m.effective_dt = (SELECT MAX(effective_dt) FROM table1 x 
WHERE x.effective_dt <= a1.value_dt)
于 2012-07-11T20:33:04.187 に答える