如何获取 GROUP_BY 子句中的值列表?

2021-12-27 00:00:00 sql group-by sybase

如果我在表格中有这样的数据

If I have data like this in a table

id   data
--   ----
1    1
1    2
1    3
2    4
2    5
3    6
3    4

如何在查询中(在 sybase 服务器上)获得这样的结果?

How do I get results like this in a query (on sybase server)?

id   data
--   ----
1    1, 2, 3
2    4, 5
3    6, 4

推荐答案

我知道在 MySQL 中有 GROUP_CONCAT 并且在 Sybase 我认为它是 LIST 如另一个答案所述:

I know that in MySQL there is GROUP_CONCAT and in Sybase I think it's LIST as stated in another answer:

SELECT id, LIST(data||', ')
FROM yourtable
GROUP BY id

相关文章