我從一個表中的SQL Server以下行2008 R2分離行使用CTE
+-------------------------------------------+
| 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的字段將被遞增(在一個月的間隔),所以輸出看起來像這樣:
+-----------+-----------+-------+
| 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可以做到這一點嗎?
演示? – Bridge
我應該提到它。 SQL Server – kadourah
我不認爲我理解這個...... :) – codingbiz