I'm trying to set the maximum number to "max" An error occurred:
Error code: 1111. Invalid use of group function 0.000 seconds
SELECT max(count(*)) as max FROM ticket group by fan_fan_id;
I'm not sure what the problem is here and I'd be happy to get some help here - and I need to fix it without the "limit 1" option
P粉9492671212024-04-05 09:43:50
SQL does not allow nested aggregate functions like the example you have shown.
The parameters of aggregate functions must be scalar expressions, not aggregate expressions.
You can do what you want:
SELECT MAX(c) FROM (SELECT COUNT(*) AS c FROM ticket GROUP BY fan_fan_id) AS t;
Or another way is to sort by value in descending order and return only the first count:
SELECT COUNT(*) AS c FROM ticket GROUP BY fan_fan_id ORDER BY c DESC LIMIT 1;