我有2個表,一個與每天連續日期/價格:鏈接連續日期一個表到另一個非連續
fs_perm_sec_id date p_price
KX8CBL-S-GB 2014-02-21 3.3515
KX8CBL-S-GB 2014-02-20 3.345
KX8CBL-S-GB 2014-02-19 3.3575
KX8CBL-S-GB 2014-02-18 3.297
,另一個零星日期項:
fs_perm_sec_id split_date p_split_factor
KX8CBL-S-GB 1998-07-06 0.333333015
KX8CBL-S-GB 1991-02-04 0.970365703
KX8CBL-S-GB 1987-07-06 0.333333015
KX8CBL-S-GB 1985-05-03 0.983739793
我我喜歡加入他們,這樣我的日日期就在第一列,然後是最近的拆分和拆分因子的日期,直到日期日期=拆分日期(1998-07-06),然後是它會返回下一個分割日期(1991-02-04),直到每日價格日期達到該點爲止......等等。
所以:
Date Split_Date Split_factor
2014-02-21 1998-07-06 0.333333015
2014-02-20 1998-07-06 0.333333015
2014-02-19 1998-07-06 0.333333015
...
1998-07-06 1998-07-06 0.333333015
1998-07-05 1991-02-04 0.970365703
1998-07-04 1991-02-04 0.970365703
...
你用什麼RDBMS? –
MS-SQL Server 2008 R2 –