【发布时间】:2016-08-23 15:45:55
【问题描述】:
我有以下租约表
Lease_id Apt_id Resident_id Start_Date End_Date Upfront_Amt Monthly_Fee
101 110 1001 02/01/2015 07/31/2015 250 500
102 111 1002 03/01/2015 02/29/2016 1000 2000
103 112 1003 04/01/2015 03/31/2016 750 1500
我想计算的是月费收入的预测。 例如:
01/2015 0 (No lease active)
02/2015 500 (From Lease 101)
03/2015 500 + 2000 (From Lease 101 and 102)
04/2015 500 + 2000 + 1500 (From Lease 101, 102 and 103)
:
:
08/2015 2000 + 1500 (From lease 102 and 103)
etc..
有没有办法通过单个查询有效地做到这一点?
【问题讨论】:
标签: sql database sum projection