Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ember.js/4.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 - Fatal编程技术网

如何在MySQL中导出单个字段中的值列表?

如何在MySQL中导出单个字段中的值列表?,mysql,Mysql,我想将表A和表B连接起来,其中B.c是一个以列表形式返回多个字符串的列。当我做一个内部连接时 select A.x, B.c from A join B on A.y=B.y 每次观察,我都会得到一个带有[列表中的值数]行的输出。是否有办法将列表写入结果表中的单个字段中,以便每次观察都得到一行 更新: select profiles.name, profiles.street_no, profiles.street_name, profiles.postal_code, profiles.ci

我想将表A和表B连接起来,其中B.c是一个以列表形式返回多个字符串的列。当我做一个内部连接时

select A.x, B.c
from A
join B
on A.y=B.y
每次观察,我都会得到一个带有[列表中的值数]行的输出。是否有办法将列表写入结果表中的单个字段中,以便每次观察都得到一行

更新:

select profiles.name, profiles.street_no, profiles.street_name, profiles.postal_code, profiles.city, profiles.country_code, profiles.owner, profiles_emails.email, profiles_telephones.telephone, clusters.main_topic, group_concat(profiles_tags.tag)
from profiles
    join profiles_emails
        on profiles.id=profiles_emails.profiles_id 
    join profiles_telephones
        on profiles.id=profiles_telephones.profiles_id
    join profiles_tags
        on profiles.id=profiles_tags.profiles_id
    join profiles_clusters
        on profiles_clusters.profiles_id=profiles.id
            join clusters
                on profiles_clusters.clusters_id=clusters.id
group by profiles.city, profiles.name, profiles.street_no, profiles.street_name, profiles.postal_code, profiles.country_code, profiles.owner, profiles_emails.email, profiles_telephones.telephone, clusters.main_topic

当然,group by占用了太多的时间,所需的输出只是一个表,其中包含所有选定列,最后一列为列表。

似乎您需要group_concat。。 假设每个a.x值有几个b.c值,则可以使用一个组,例如:

  select A.x, group_concat(B.c)
  from A
  join B  on A.y=B.y
  group by a.x

发布一些示例数据和预期输出。谢谢,这很有帮助。虽然我真的不明白为什么我需要按我在“选择”中指定的每一列进行分组,另请参见,还是我误解了什么?如果您更新了您的问题并添加了您正在使用的代码,我可以评估您真正的问题。。最好是添加真实数据样本和预期结果。。不管怎么说,你们都在使用mysql 5.7,你们必须在group by中添加所有不在聚合函数中的列(这是group by的正确方式)…好的,这样做了。我认为我们在正确的轨道上,现在查询显然需要永远使用group by中的这么多列…group by的成本与列无关。。(最终与所涉及行的基数有关…)但对我来说,如果查询速度慢,这可能与连接有关。。然后确保对join中涉及的所有列都有适当的索引。。尤其是大桌子…无论如何。。我的答案正确吗?在什么之前。。在分组之前。。没有。。聚合函数(组_concat)。。每个表中有多少行。?。并检查是否存在正确的索引。。