如何在 MySql 中的 SQL 查询中将行折叠成逗号分隔的列表 [英] How to collapse rows into a comma-delimited list in an SQL Query in MySql

查看:43
本文介绍了如何在 MySql 中的 SQL 查询中将行折叠成逗号分隔的列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 T-SQL 中,在 SQL 查询中将相关值连接成逗号分隔的字符串相对简单(请参阅此处:将 SELECT 的行折叠为字符串的最佳方法是什么? 在这里:什么是将 SELECT 的行折叠为字符串的最佳方法?).后一个链接准确地描述了我需要做什么,但我需要在 MySql 中进行,而在 T-SQL 中工作的查询在 MySql 中不起作用.任何 MySql 专家都知道如何做到这一点?

It is relatively simple in T-SQL to concatenate related values into a comma delimited string in an SQL Query (see here: What is the best way to collapse the rows of a SELECT into a string? and here: What is the best way to collapse the rows of a SELECT into a string?). The latter link describes exactly what I need to do, but I need to do it in MySql, and the query that works in T-SQL doesn't work in MySql. Any MySql experts out there know how to do this?

谢谢!

推荐答案

被称为group_concat

select group_concat(your_id) from your_table

这篇关于如何在 MySql 中的 SQL 查询中将行折叠成逗号分隔的列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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