我試圖用2008年MSSQL,使一個新的觀點: 表1有客戶ID和事務ID 表1SQL視圖 - 從三個表將多個行到
CustomerID TransactionID
1 1
1 2
表2有采購交易和產品ID
TransactionID ProductID
1 x
2 y
表3有產品名稱
ProductID Name
1 x
2 y
我認爲我想提出應該顯示
CustomerID Product Name
1 x, y
當我使用下面的查詢:
SELECT table1. CustomerID, table3.Name
FROM table1 LEFT OUTER JOIN
Table2 ON table2. TransactionID = table1.VisitId LEFT OUTER JOIN
Table3 ON table2. ProductID = Table3. ProductID
GROUP BY table1. CustomerID, table3.Name
我得到提前
CustomerID Product Name
1 x
1 y
感謝
[T-SQL的可能重複。如何在一個SELECT中創建列表爲逗號分隔的字符串?](http://stackoverflow.com/questions/7621432/t-sql-how-create-list-as-comma-separated-string-in-one-select)從昨天 – gbn
可能重複[sql連接角色](http://stackoverflow.com/questions/6624347/sql-concatenated-roles) –