慕娘9325324
一个好问题。应该告诉你,花了一些时间来破解这个。这是我的结果。DECLARE @TABLE TABLE( ID INT, USERS VARCHAR(10), ACTIVITY VARCHAR(10), PAGEURL VARCHAR(10) )INSERT INTO @TABLE VALUES (1, 'Me', 'act1', 'ab'), (2, 'Me', 'act1', 'cd'), (3, 'You', 'act2', 'xy'), (4, 'You', 'act2', 'st')SELECT T1.USERS, T1.ACTIVITY, STUFF( ( SELECT ',' + T2.PAGEURL FROM @TABLE T2 WHERE T1.USERS = T2.USERS FOR XML PATH ('') ),1,1,'') FROM @TABLE T1 GROUP BY T1.USERS, T1.ACTIVITY