Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/57.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_Group Concat - Fatal编程技术网

Mysql组目录。。。没有得到我想要的结果

Mysql组目录。。。没有得到我想要的结果,mysql,group-concat,Mysql,Group Concat,我有一个返回以下行的查询: parent_id child_id 12882 12856 12882 12857 12882 12858 12884 12863 12884 12864 12884 12865 12884 12866 当我添加GROUP_CONCAT(child_id)时,它只返回一行,其中包含第一个parent_id和所有child_

我有一个返回以下行的查询:

parent_id   child_id
    12882       12856
    12882       12857
    12882       12858
    12884       12863
    12884       12864
    12884       12865
    12884       12866
当我添加GROUP_CONCAT(child_id)时,它只返回一行,其中包含第一个parent_id和所有child_id的CONCAT'ed

我需要的是查询返回,其中GROUP_CONCAT为每个父ID提供1条记录,CONCAT仅为该父ID提供子ID。。。想法

  parent_id   child_id
  12882     12856, 12857, 12858
  12884     12863, 12864, 12865, 12866

用GROUPBY子句试试这个

SELECT parent_id, GROUP_CONCAT(child_id)  from tablename group by parent_id

请显示您的查询sqlnaveen goyal的ans对您有用您需要一个GROUP BY子句,听起来好像缺少了它