Aggregate function in MySQL - list (like LISTAGG in Oracle)

青春壹個敷衍的年華 提交于 2019-11-27 01:57:41

You're looking for GROUP_CONCAT()

Try this:

select group_concat(MyString separator ', ') as myList from table
where id < 4

Of course, you can group by the results.

As of MySQL 5.7.22 you can also use two JSON aggregation functions: JSON_ARRAYAGG or JSON_OBJECTAGG. You can combine these together with MySQL's JSON functions to get results aggregated as JSON. Unlike GROUP_CONCAT, there is no MySQL configuration parameter which would limit the size of the returned value, other than max_allowed_packet (which affects all queries).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!