1",:select=>"school_id,group_concat(id SEPARATOR ',') as f-6ren">
gpt4 book ai didi

mysql - group_concat 不显示所有值 mysql

转载 作者:行者123 更新时间:2023-11-30 22:21:50 26 4
gpt4 key购买 nike

ModelName.all(:having=>"count(receipt_no)>1",:select=>"school_id,group_concat(id SEPARATOR ',') as f_ids,receipt_no,count(distinct id) as id_count,count(receipt_no) as  rec_count",:conditions=>"receipt_no is not null",:group=>"receipt_no")

输出是

 +------------+-----------+----------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-----------+
| receipt_no | school_id | id_count | f_ids | rec_count |
+------------+-----------+----------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-----------+
| 1261 | 1783 | 2 | 557660,557661 | 2 |
| 14/15- | 1783 | 1209 | 68352,77056,113664,56320,68353,77057,113665,56321,68354,56322,68355,81923,173571,113667,56323,68356,94980,56324,68357,56325,68358,80390,56326,68359,80391,110599,56327,80392,885... | 1209 |
| 15- | 1783 | 112 | 344067,344068,344069,344070,344075,326923,373261,373262,345882,360218,344091,361755,347685,341542,347689,360233,351530,358705,352829,324674,341576,324684,360018,368469,371541,3... | 112 |

这里的group_concat并没有显示所有的值,而是显示项目的计数与计数收据编号相同。假设 f_ids 列中的项目超过 200 个字符,那么它不会显示所有值。在其他情况下,它将显示正确的值

最佳答案

我得到了解决方案

SET SESSION group_concat_max_len = 1000000;

在 MySQL 控制台中运行这段代码,然后这段代码会将默认的 group_concat 字符限制更改为 1000000 个字符。

如果你想在rails console中使用,你可以通过以下方式使用

sql = "SET SESSION group_concat_max_len = 1000000"
ActiveRecord::Base.connection.execute(sql)

请注意:此配置仅在该 session 中有效

关于mysql - group_concat 不显示所有值 mysql,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36469193/

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