作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
<分区>
我正在尝试从 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)。
我是一名优秀的程序员,十分优秀!