如何用两个日期参数计算两个日期之间的利率

时间:2014-02-22 09:30:55

标签: tsql

交易表

TransactionDate   Balance   
2014-03-30        50000
2014-04-05        2000
2014-04-10        1000
2014-04-20        25000
2014-05-05        10000

利率表

FromDate    ToDate      Rate
2014-02-28  2014-04-01  2.1%
2014-04-02  2014-04-15  2.2%
2014-04-16  2014-04-21  2.7%
2014-04-22  2014-05-02  2.8%
2014-05-03  2015-03-31  2.9%

以下格式

所需的SQL查询输出
FromDate: 2014-04-01
ToDate:   2014-05-30

**输出表格如下**

Balance FromDate    ToDate        Rate 

50000   2014-03-31  2014-04-01    2.1
50000   2013-04-01  2014-04-05    2.2
52000   2014-04-05  2014-04-10    2.2
53000   2014-04-10  2014-04-15    2.2
53000   2014-04-15  2014-04-20    2.7
78000   2014-04-20  2014-04-21    2.7
78000   2014-04-21  2014-05-02    2.8
78000   2014-05-02  2014-05-05    2.9
79000   2014-05-05  2014-05-30    2.9

0 个答案:

没有答案