我有以下数据,并希望找到一种使用 MS Access SQL 或 MS SQL Server 创建查询以将所有内容合并到一行的方法。
RespondentID Name EID Phone Why How Contact
1809593812 Testing 0
1809593812 Testing 0
1809593812 19091193 0
1809593812 Jennifer 0
1809593812 8885555555 0
我希望它看起来像:
RespondentID Name EID Phone Why How Contact
1809593812 Jennifer 19091193 8885555555 Testing Testing 0
这可以使用 MS Access SQL Query 或 MS SQL Server Query 吗?
这样的记录还有很多。我无法控制它的布局,因为它是每天从外部来源导出的。
到目前为止,我在 MS Access Query 中拥有的是:
SELECT DISTINCT dbo_ResponsesText.RespondentID,
IIf(dbo_ResponsesText.Key1=4383976121,ResponseText,Null) AS Name,
IIf(dbo_ResponsesText.Key1=4383976120,ResponseText,Null) AS EID,
IIf(dbo_ResponsesText.Key1=4388819402,ResponseText,Null) AS Phone,
IIf(dbo_ResponsesText.QuestionID=340372755,ResponseText,Null) AS Why,
IIf(dbo_ResponsesText.QuestionID=340372805,ResponseText,Null) AS How,
IIf(dbo_Responses.Key1=4305593988,-1,0) AS Contact
FROM dbo_ResponsesText
INNER JOIN dbo_Responses ON dbo_ResponsesText.RespondentID = dbo_Responses.RespondentID
ORDER BY dbo_ResponsesText.RespondentID
实际表结构:
dbo_ResponsesText Table
ID RespondentID CollectorID QuestionID Key1 ResponseText DateAdded
1 1821607396 25982810 340372755 0 Name,EID,etc. 5/1/2012 3:29:00 PM
dbo_Responses Table:
RespondentID CollectorID QuestionID Key1 Key2 Key3
1809593812 25982810 340372567 4308039090 0 0