select max() from count() [duplicate]

2019-03-23 08:37发布

问题:

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

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?..

回答1:

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;


标签: mysql count max