我有这个查询:
SELECT DISTINCT
f1.CourseEventKey,
STUFF
(
(
SELECT
'; ' + Title
FROM
(
SELECT DISTINCT
ces.CourseEventKey,
f.Title
FROM
CourseEventSchedule ces
INNER JOIN Facility f
ON f.FacilityKey = ces.FacilityKey
WHERE
ces.CourseEventKey IN
(
SELECT CourseEventKey
FROM @CourseEvents
)
) f2
WHERE
f2.CourseEventKey = f1.CourseEventKey
FOR XML PATH('')
)
, 1, 2, '')
FROM
(
SELECT DISTINCT
ces.CourseEventKey,
f.Title
FROM
CourseEventSchedule ces
INNER JOIN Facility f
ON f.FacilityKey = ces.FacilityKey
WHERE
ces.CourseEventKey IN
(
SELECT CourseEventKey
FROM @CourseEvents
)
) f1; …Run Code Online (Sandbox Code Playgroud)