Getting SUM () from COUNT ()

Is there a way in mysql to achieve

SELECT COUNT( SUM(field2) ) FROM TABLE WHERE field1='value' GROUP BY field2

Return one row with the total amount of the calculated field 2.

Field 1 && Field 2 is not unique.

If you need more information, just let me know.

Edit: I did not think it was clear. I need COUNT from COUNT.

so that all the calculated values ​​from field 2. this can be achieved by getting the number of rows, but I chose for this:

SELECT COUNT( first_count ) total_count FROM 
( SELECT COUNT( field2 ) as first_count FROM TABLE
  WHERE field1='value' GROUP BY field2 )t1

Or is there a faster request?

Greetings!

+3
source share
2 answers

Your update

SELECT COUNT( first_count ) total_count FROM 
( 
  SELECT COUNT( field2 ) as first_count FROM TABLE
  WHERE field1='value' GROUP BY field2 )t1
)

Is there a COUNT score for each field2, which matches the number of unique fields2

SELECT COUNT(DISTINCT field2) FROM TABLE WHERE field1='value'
+5
source

I think you mean:

SELECT field2
     , field2 * COUNT(*)
FROM TABLE
WHERE field1 = 'value'
GROUP BY field2

also:

No GROUPED BY. Exist:GROUP BY


, , :

SELECT COUNT( DISTINCT field2 ) AS total_count
FROM TABLE
WHERE field1 = 'value'
+5

All Articles