0
請想象下表:SQL Server查詢。在查詢中轉換數據?
發票
|Invoice ID | Invoice Date |
---------------------------------
|1 | 01-11-12 |
|2 | 01-11-12 |
服務
|Service ID | Service Date | Invoice ID |
-------------------------------------------------
|1 | 01-11-12 | 1 |
|2 | 01-11-12 | 1 |
|3 | 02-11-12 | 1 |
|4 | 03-11-12 | 1 |
我想返回一個數據集,像這樣:
|Invoice ID | Invoice Date | Service ID | Transformed Service Date | Real Service Date |
--------------------------------------------------------------------------------------------------------
|1 | 01-11-12 | 1 | 01-11-12 | 01-11-12 |
|1 | 01-11-12 | 2 | 01-11-12 | 01-11-12 |
|1 | 01-11-12 | 3 | 01-11-12 | 02-11-12 |
|1 | 01-11-12 | 4 | 01-11-12 | 03-11-12 |
|1 | 01-11-12 | 1 | 02-11-12 | 01-11-12 |
|1 | 01-11-12 | 2 | 02-11-12 | 01-11-12 |
|1 | 01-11-12 | 3 | 02-11-12 | 02-11-12 |
|1 | 01-11-12 | 4 | 02-11-12 | 03-11-12 |
|1 | 01-11-12 | 1 | 03-11-12 | 01-11-12 |
|1 | 01-11-12 | 2 | 03-11-12 | 01-11-12 |
|1 | 01-11-12 | 3 | 03-11-12 | 02-11-12 |
|1 | 01-11-12 | 4 | 03-11-12 | 03-11-12 |
請注意所有服務在每個服務日期的返回情況。我希望這是可能的。我正在使用此查詢來幫助在SQL Server報告中進行分組。
謝謝你的幫助。
爲什麼不學習查詢? –