-2
我有一個問題在下面提到,不能做到沒有SQL,因爲我有200萬行。填補日期範圍的空白 - SQL
我有一個表Table1
其中我有物品/祿提供給定日期範圍的促銷價格。此外,我還有一個表Table 2
在那裏我有基準價從2015年的每個項目/ LOC - 2017年,我必須用填寫表1給出
表1差距:
+-----------------------------------------------------------+
| Item | Location | Startdate | EndDate | Promoted Price |
+-------+----------+-----------+-----------+----------------+
| Item1 | Loc1 | 6/23/2015 | 6/24/2015 | 22 |
| Item1 | Loc1 | 7/10/2015 | 7/17/2015 | 30 |
| Item1 | Loc1 | 7/24/2015 | 7/31/2015 | 30 |
| Item2 | Loc2 | 6/21/2015 | 8/7/2015 | 25 |
| Item2 | Loc2 | 8/28/2015 | 9/4/2015 | 27 |
| Item2 | Loc2 | 9/11/2015 | 9/18/2015 | 28 |
+-------+----------+-----------+-----------+----------------+
表2
+--------------------------------------------------------+
| Item | Location | Startdate | EndDate | Full_Price |
+-------+----------+-----------+------------+------------+
| Item1 | Loc1 | 1/1/2015 | 12/31/2017 | 32 |
| Item2 | Loc2 | 1/1/2015 | 12/31/2017 | 24 |
| Item3 | Loc3 | 1/1/2015 | 12/31/2017 | 54 |
| Item4 | Loc4 | 1/1/2015 | 12/31/2017 | 67 |
| Item5 | Loc5 | 1/1/2015 | 12/31/2017 | 39 |
| Item6 | Loc6 | 1/1/2015 | 12/31/2017 | 48 |
| Item7 | Loc7 | 1/1/2015 | 12/31/2017 | 63 |
| Item8 | Loc8 | 1/1/2015 | 12/31/2017 | 52 |
| Item9 | Loc9 | 1/1/2015 | 12/31/2017 | 51 |
+-------+----------+-----------+------------+------------+
結果應該是這樣的:
| Item | Location | Startdate | EndDate | Promoted Price |
+-------+----------+-----------+-----------+----------------+
| Item1 | Loc1 | 6/23/2015 | 6/24/2015 | 22 |
| Item1 | Loc1 | 6/25/2015 | 7/9/2015 | 32 |
| Item1 | Loc1 | 7/10/2015 | 7/17/2015 | 30 |
| Item1 | Loc1 | 7/18/2015 | 7/23/2015 | 32 |
| Item1 | Loc1 | 7/24/2015 | 7/31/2015 | 30 |
嗨,傑西,我可以看到行1和第一表(表1)。我需要從startdate日期2015年6月25日至2015年9月7日創建一條新記錄,對於此記錄,我需要從表2中獲取值,這是缺口的缺省值(缺少某些日期的記錄) – user6777467