1 CREATE TABLE SC 2 3 ( 4 5 Student NVARCHAR(50), 6 7 Course NVARCHAR(50) 8 9 ) 10 11 INSERT INTO SC 12 13 SELECT N‘张三‘,N‘大学语文‘ UNION ALL 14 15 SELECT N‘李四‘,N‘大学语文‘ UNION ALL 16 17 SELECT N‘张三‘,N‘书法鉴赏‘ UNION ALL 18 19 SELECT N‘张三‘,N‘音乐赏析‘ UNION ALL 20 21 SELECT N‘李四‘,N‘电影赏析‘
1 SELECT DISTINCT [Student],STUFF(( 2 3 SELECT ‘,‘+[Course] FROM [dbo].[SC]WHERE Student = A.Student FOR XML PATH(‘‘) 4 5 ),1,1,‘‘)AS Course 6 7 FROM [dbo].[SC] AS A 8
时间: 2024-10-18 17:39:01