我正在尝试找出如何为每个资产返回一行,该行显示累计期间的总天数。但是,我只想根据StartDate是否在上一个周期的EndDate的10天内添加某些周期。
示例数据中的TotalDays列:如果“期间”没有EndDate,则总天数是Today(13/10/2018)减去StartDate。
预期输出表的细分:
第1行/资产1:TotalDays为278,因为
第2行/资产2:TotalDays为120,因为
第3行/资产3:TotalDays为66,因为
如果资产没有未清期间,它将不会显示在输出中。
很高兴澄清任何事情,因为我知道这有点奇怪!
非常感谢。
数据样本:
+-----+---------+--------+------------+------------+-----------+--------------------------------------+--------+
| Row | AssetID | Period | StartDate | EndDate | TotalDays | DaysBetweenEndDateAndStartDateOfNext | Status |
+-----+---------+--------+------------+------------+-----------+--------------------------------------+--------+
| 1 | 1 | 1 | 01/01/2018 | 05/03/2018 | 63 | NULL | Closed |
| 2 | 1 | 2 | 06/03/2018 | 04/04/2018 | 29 | 1 | Closed |
| 3 | 1 | 3 | 10/04/2018 | NULL | 186 | 6 | Open |
| 4 | 2 | 1 | 15/06/2018 | NULL | 120 | NULL | Open |
| 5 | 2 | 2 | 01/07/2018 | NULL | 104 | NULL | Open |
| 6 | 3 | 1 | 01/02/2018 | 10/02/2018 | 9 | NULL | Closed |
| 7 | 3 | 2 | 08/08/2018 | NULL | 66 | 179 | Open |
+-----+---------+--------+------------+------------+-----------+--------------------------------------+--------+
预期输出:
+-----+---------+------------+---------+-----------+
| Row | AssetID | StartDate | EndDate | TotalDays |
+-----+---------+------------+---------+-----------+
| 1 | 1 | 01/01/2018 | NULL | 278 |
| 2 | 2 | 15/06/2018 | NULL | 120 |
| 3 | 3 | 08/08/2018 | NULL | 66 |
+-----+---------+------------+---------+-----------+