gpt4 book ai didi

mysql - 如何在 MySQL 中选择列作为 CSV?

转载 作者:搜寻专家 更新时间:2023-10-30 19:55:33 26 4
gpt4 key购买 nike

这是表格

id    name
----------
1 john
2 dave
3 eve

select * from table 将给我们

id    name
----------
1 john
2 dave
3 eve

您将如何查询以获得以下输出?

id       name
----------------------
1,2,3 john,dave,eve

最佳答案

您需要先增加变量 group_concat_max_len 的值,这样数据才不会在 group_concat 中被截断。通过命令检查变量值:

show variables like 'group_concat_max_len'

并将其增加为:

set global group_concat_max_len = 160000.

在此之后使用查询:

SELECT GROUP_CONCAT(id), GROUP_CONCAT(name) FROM   table_name

关于mysql - 如何在 MySQL 中选择列作为 CSV?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32624345/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com