在SQLite中,SQL SERVER中“ FOR XML PATH('')”的等效项是什么?
示例数据如下
Id | Value
-----+------
0001 | IN
0001 | ME
0001 | OH
0001 | ON
0002 | AC
0002 | ON
0002 | VI
0002 | ZO
0003 | ME
0003 | OO
0003 | PS
0003 | QA
想获取数据
Id | Value
-----+------
0001 | IN,ME,OH,ON
0002 | AC,ON,VI,ZO
0003 | ME,OO,PS,QA
有效的SQL Server变体:
SELECT [id],RIGHT([VALUE],LEN([VALUE])-1) AS [VALUE] FROM (
SELECT [id],(SELECT ',' + [VALUE] FROM @TEMP
WHERE [id] = a.[id] FOR xml path('')
) [VALUE]
FROM @TEMP a
GROUP BY [id]
) X
我对如何在SQLite中完成此操作感兴趣?
答案 0 :(得分:1)
据我所知,没有办法对您似乎在输出中期望的值进行排序。如果您不需要该命令,请考虑使用GROUP_CONCAT
:
SELECT Id, GROUP_CONCAT(Value) Value
FROM yourTable
GROUP BY Id
ORDER BY Id;