Aggregate function in MySQL - list (like LISTAGG in Oracle)(MySQL 中的聚合函数 - 列表(如 Oracle 中的 LISTAGG))
问题描述
我需要返回字符串列表的函数.
I need function, that returns list of strings.
我在表中有这样的数据:
I have data in table like this:
Id MyString
------------------------
1 First
2 Second
3 Third
4 Fourth
我需要这样的功能(类似这样的东西在 oracle 中有效):
I need function like this (something like this works in oracle):
select LISTAGG(MyString, ', ') as myList where id < 4
返回如下内容:
myList
------------------------
First, Second, Third
有什么想法吗?
推荐答案
您正在寻找 GROUP_CONCAT()
试试这个:
select group_concat(MyString separator ', ') as myList from table
where id < 4
当然,你可以group by
结果.
这篇关于MySQL 中的聚合函数 - 列表(如 Oracle 中的 LISTAGG)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!