本文介绍了从count()中选择max()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要为每个用户找到最多的操作

I need to find maximum of actions per user

表列: action_id action_status 用户

请求:

SELECT MAX(`counted`) FROM
(
SELECT COUNT(*) AS `counted`
FROM `table_actions`
WHERE `status` = "good"
GROUP BY `user`
)

错误消息:每个派生表必须有自己的别名

error message: "Every derived table must have its own alias"

有什么问题?

推荐答案

这意味着MySQL坚持要给内部 SELECT 一个名字,例如:

That just means MySQL insists that you give the inner SELECT a name, like:

SELECT MAX(counted) FROM
(
    SELECT COUNT(*) AS counted
    FROM table_actions
    WHERE status = "good"
    GROUP BY user
) AS counts;

这篇关于从count()中选择max()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-07 06:46