Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/63.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何将多个MySQL行连接到一个字段中?_Mysql_Sql_Concat - Fatal编程技术网

如何将多个MySQL行连接到一个字段中?

如何将多个MySQL行连接到一个字段中?,mysql,sql,concat,Mysql,Sql,Concat,使用MySQL,我可以执行以下操作: SELECT c.id_category, c.id_category_type, c.label, c.id_parent FROM category c WHERE c.id_category_type < 3 ORDER BY c.id_category_type; 但是相反,我只想要concat行,我有一个id\u类别和id\u父项 示例: 我在上查找了一个函数,它看起来不像CONCAT或CONCAT\WS函数接受结果集,那么这里有人知道

使用
MySQL
,我可以执行以下操作:

SELECT c.id_category, c.id_category_type, c.label, c.id_parent
FROM category c
WHERE  c.id_category_type < 3 
ORDER BY c.id_category_type;
但是相反,我只想要
concat
行,我有一个
id\u类别
id\u父项

示例:

我在上查找了一个函数,它看起来不像
CONCAT
CONCAT\WS
函数接受结果集,那么这里有人知道如何执行此操作吗?

测试此操作:

SELECT category.id_category, category.id_category_type, 
CONCAT(category.label, '-', parents.label), category.id_parent  FROM category INNER JOIN
(SELECT id_category AS id, label FROM category WHERE id_parent = -1) AS parents
ON parents.id = category.id_parent WHERE  category.id_category_type < 3 
ORDER BY category.id_category_type;
然后,您可以像使用任何其他表一样使用“父”表并构建联接查询

Autre-Demande d'information
Mairie-Demande d'information
Stationnement-Demande d'information
Autre-Réclamation
Familles-Réclamation
TESTDOMAINE-TEST
SELECT category.id_category, category.id_category_type, 
CONCAT(category.label, '-', parents.label), category.id_parent  FROM category INNER JOIN
(SELECT id_category AS id, label FROM category WHERE id_parent = -1) AS parents
ON parents.id = category.id_parent WHERE  category.id_category_type < 3 
ORDER BY category.id_category_type;
(SELECT id_category AS id, label FROM category WHERE id_parent = -1) AS parent