我有兩張工作表。第一張表#CustomerList
我手動初始化值。然後我創建第二個表#CustomerListWithRank_Id
,它基於第一個表#CustomerList
。如何從我的表中選擇不同的列?
第一和第二臺之間的唯一不同的是,第二個表#CustomerListWithRank_Id
有一欄,讓每一個它的ROWNUMBER我用進一步下跌在我的SQL代碼時,我遍歷該錶行。
所以我的問題是,我只是想初始化#CustomerListWithRank_Id
只有來自列[FileName]的唯一值,我該怎麼做?
SELECT '3004' Customer_No,'831001' DDD_Reference_No,'varer831.csv' [FileName]
INTO #CustomerList -- DROP TABLE #CustomerList
UNION ALL SELECT '3002' Customer_No,'199001' DDD_Reference_No,'varer199.csv' [FileName]
UNION ALL SELECT '3003' Customer_No,'199002' DDD_Reference_No,'varer199.csv' [FileName]
-
SELECT *, ROW_NUMBER() OVER (ORDER BY Customer_No) AS 'Rank_Id'
INTO #CustomerListWithRank_Id --DROP TABLE #CUstomerListWithRank_ID
FROM #CustomerList
如果我使用GROUP BY [文件名]在上面的查詢我得到這個錯誤:
Msg 8120, Level 16, State 1, Line 1
Column '#CustomerList.Customer_No' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
感謝您的幫助 –