我有一个看起来像这样的表:
Project | State
----------------
1 | A
2 | A
2 | F
3 | A
3 | F
3 | P
4 | S
5 | C
我想要的是得到一张这样的表:
Project | State
----------------
1 | A
2 | AF
3 | AFP
4 | S
5 | C
是否可以这样做?
答案 0 :(得分:2)
SELECT Project,
(SELECT State + ''
FROM table t
WHERE t.project = m.project
FOR XML PATH(''))
FROM table m
GROUP BY Project