MySQL 从 count() 中选择 max()

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10363518/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 13:09:31  来源:igfitidea点击:

select max() from count()

mysqlcountmax

提问by Zdomb

Possible Duplicate:
every derived table must have its own alias

可能的重复:
每个派生表必须有自己的别名

I need to find maximum of actions per user

我需要找到每个用户的最大操作数

table columns: action_id, action_status, user

表列:action_id, action_status,user

request:

要求:

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"

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

what is wrong?..

怎么了?..

回答by Michael Slade

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

这只是意味着 MySQL 坚持你给内部SELECT一个名字,比如:

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