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?..
And the short answer to the above question is, no. You can't. It is not possible to nest aggregate functions.
Yes, when using the COUNT() function on a column in SQL, it will include duplicate values by default. It essentially counts all rows for which there is a value in the column. If you wanted to count only the unique values in a column, then you can utilize the DISTINCT clause within the COUNT() function.
Select TOP 1 City, Count(City) AS 'MAX_COUNT' FROM Customer Group By City Order By 'MAX_COUNT' DESC; Hope this simple query will help many one. Show activity on this post. If you are using Oracle Database, you can simply use stats_mode function this will return single value with highest occurrences.
Yes, we can ignore duplicate rows in COUNT using DISTINCT.
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;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With