更新时间:2022-12-03 18:55:04
(已编辑以给出两列的首选顺序)
(Edited to give the preferred ordering for the two columns)
SELECT a.Id,
a.Name,
STUFF(MIN(STR(b.Id, 10) + b.Information), 1, 10, '') AS InformationA,
CASE
WHEN COUNT(b.Id) = 2 THEN STUFF(MAX(STR(b.Id, 10) +
b.Information), 1, 10, '')
END AS InformationB
FROM TableA a
LEFT JOIN TableB b
ON a.Id = b.NameId
GROUP BY a.Id,
a.Name