【发布时间】:2019-09-11 14:06:59
【问题描述】:
如何将具有相同值的多行以逗号分隔并按升序组合在单列中(在 SQL Server 中)返回到单行中?
表2
------------
col1 | col2 | col3
----------------------
1 | line1 | 2
1 | line2 | 1
1 | line3 | 4
2 | line4 | 1
2 | line5 | 3
2 | line6 | 2
3 | line7 | 2
3 | line8 | 1
想要的结果按照 col3 升序排列:
Col1 | col2
----------------------------
1 | Line2,Line1,Line3
2 | Line4,Line6,Line5
3 | Line8,Line7
【问题讨论】:
-
您使用的是哪个 RDMS?而且看起来您使用的不是表 2?
-
现在我想更清楚了,我已经更新了问题:)
-
你的 rdbms 是什么? Sql Server、postgres、oracle?什么版本?
-
rdbms 是 SQL server
标签: sql sql-server string-aggregation