mysql - 连接子查询的输出?

标签 mysql

我有一个会返回值的查询,但我需要将它们作为用逗号分隔的单个输出..

所以我尝试用逗号连接输出,但它不起作用?

select id from videos where duration=0;  /// this would return some rows

我尝试了 concat 和 concat_ws 但没有用

select concat(select concat(id,',') from videos where duration=0);
select concat((select id from videos where duration=0),',');
select concat_ws(',',(select id from videos where duration=0));

我需要所有行的 id 和逗号分隔符

例如输出应该是 1,4,6,78,565

有什么想法吗?

最佳答案

这就是 group_concat可以。

select group_concat(id) as video_list
from videos 
where duration=0

关于mysql - 连接子查询的输出?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3812864/

相关文章:

php - 从数据库中获取列名

MySQL 返回表名和数据库中所有表的字段数据

MySQL 准备语句语法

mysql - 如何将我的列合并为一个以在 MySQL 中创建 URI?

mysql - 仅在(mysql)表中存储日期部分

php - 在 Ubuntu 14 上使用 PHP 连接到 MySQL

PHP和mysql的问题

mysql - 如果从查询中设置@VARIABLE,则无法使用 SQLDataProvider

php - 根据到当前 GPS 位置的距离重新排序 <select> 位置列表

mysql - 如何在 JOINED 表中使用 FIND_IN_SET?