MySQL中的汇总函数-列表(如Oracle中的LISTAGG) [英] Aggregate function in MySQL - list (like LISTAGG in Oracle)

查看:56
本文介绍了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

有什么想法吗?

推荐答案

您在寻找尝试一下:

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

当然,您可以group by结果.

这篇关于MySQL中的汇总函数-列表(如Oracle中的LISTAGG)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆