Mysql
 sql >> Datenbank >  >> RDS >> Mysql

MySQL kombiniert COUNT, MAX und SUM

Versuchen Sie Folgendes:

SELECT COL1,Max(COUNT_ID),Sum(SUM_MAX_COUNT) FROM(
SELECT COL1,
   Count(*) AS COUNT_ID,
   (SELECT Sum(Count(*))
    FROM   TABLE_NAME
    GROUP BY COL1) AS SUM_MAX_COUNT
FROM   TABLE_NAME
GROUP  BY COL1)
GROUP BY COL1;