【发布时间】:2020-11-20 08:28:42
【问题描述】:
给定下表:
+--------------------+-----------+
| Account | Company |
+--------------------+-----------+
| gloria.harding | FB |
| gloria.harding | Twitter |
| bryant.schuman | Google |
| jerry.maxwell | Apple |
| rachel.heptinstall | FB |
| rachel.heptinstall | Twitter |
| rachel.heptinstall | Instagram |
+--------------------+-----------+
我想按 Account 对结果进行分组,但我需要将组中每一行的 Company 列连接起来,并将它们全部显示在一个匿名列中,例如所以:
+--------------------+------------------------+
| Account | 'Companies' |
+--------------------+------------------------+
| gloria.harding | FB, Twitter |
| bryant.schuman | Google |
| jerry.maxwell | Apple |
| rachel.heptinstall | FB, Twitter, Instagram |
+--------------------+------------------------+
这可以在 TSQL 上实现吗?
第一个要求可以通过对Account列进行分组来轻松实现,但我不知道如何实现后者。
【问题讨论】:
-
您目前使用的是哪个 dbms?
-
@T.Peter SQL Server 2016
-
我很高兴问因为我认为
string_agg()不支持 SQL Server 2016...
标签: sql tsql sql-server-2016