Is it possible to concatenate column values into a string using CTE?

前端 未结 3 1118
野的像风
野的像风 2020-12-18 07:46

Say I have the following table:

id|myId|Name
-------------
1 | 3  |Bob 
2 | 3  |Chet
3 | 3  |Dave
4 | 4  |Jim
5 | 4  |Jose
-------------

Is

3条回答
  •  时光说笑
    2020-12-18 08:04

    A CTE is just a glorified derived table with some extra features (like recursion). The question is, can you use recursion to do this? Probably, but it's using a screwdriver to pound in a nail. The nice part about doing the XML path (seen in the first answer) is it will combine grouping the MyId column with string concatenation.

    How would you concatenate a list of strings using a CTE? I don't think that's its purpose.

提交回复
热议问题