我在 SQL Server 2008 R2 的表中有以下行
+-------------------------------------------+
| ID EntryType dt price |
+-------------------------------------------+
| 14 4 2012-11-07 0.025000 |
| 16 5 2012-11-07 0.026000 |
| 18 6 2012-11-07 0.026000 |
| 20 7 2012-11-07 0.026000 |
+-------------------------------------------+
我想做的是根据 EntryType 传播行(EntryType 不会改变)
For EntryType = 4 (1 row)
For EntryType = 5 (2 row)
For EntryType = 6 (3 row)
For EntryType = 7 (9 row)
并且 dt 字段将递增(以 Month 间隔),因此输出如下所示:
+-----------+-----------+-------+
| EntryType | dt | Price |
+-----------+-----------+-------+
| 4 | 11/7/2012 | 0.024 |
| 5 | 12/7/2012 | 0.025 |
| 5 | 1/7/2013 | 0.025 |
| 6 | 2/7/2013 | 0.026 |
| 6 | 3/7/2013 | 0.026 |
| 6 | 4/7/2013 | 0.026 |
| 7 | 5/7/2013 | 0.027 |
| 7 | 6/7/2013 | 0.027 |
| 7 | 7/7/2013 | 0.027 |
| 7 | 8/7/2013 | 0.027 |
| 7 | 9/7/2013 | 0.027 |
| 7 | 10/7/2013 | 0.027 |
| 7 | 11/7/2013 | 0.027 |
| 7 | 12/7/2013 | 0.027 |
| 7 | 1/7/2014 | 0.027 |
+-----------+-----------+-------+
是否可以使用 CTE 和 SQL 做到这一点?