gpt4 book ai didi

mysql - 如何从group_concat mysql的结果中获取最大值

转载 作者:行者123 更新时间:2023-11-29 06:35:56 24 4
gpt4 key购买 nike

<分区>

我正在尝试从 group_concat 的结果中获取最大值。

这是示例数据,以及我尝试过的内容,

+----+---------+--------------------------+
| id | user_id | comment |
+----+---------+--------------------------+
| 1 | 80 | I don't need it any more |
| 2 | 222 | Don't need this account |
| 3 | 80 | I have an other account |
| 4 | 80 | The other comment |
| 5 | 222 | some x |
+----+---------+--------------------------+
4 rows in set (0.01 sec)

我尝试了以下查询,

mysql> select max(group_concat(id  SEPARATOR ' ')), user_id from userapp_accactivitylog;

但它给我错误

ERROR 1111 (HY000): Invalid use of group function

group_concat(id) 我们会得到结果 1,2,3,4,5 。我的要求是我想从使用 group_concat 得到的结果中选择最大的数字。

希望您明白我在寻找什么,如果有办法实现以下结果,请告诉我:

+----+---------+--------------------------+
| id | user_id | comment |
+----+---------+--------------------------+
| 5 | 222 | some x |
| 4 | 80 | The other comment |
+----+---------+--------------------------+
2 rows in set (0.01 sec)

我正在尝试按 user_id 进行分组,并且我想获取 id 列中最大数量的记录(即在本例中为 5)。

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