MySQL Question

Count specific values. Mysql

I have a table that looks like:

field1 | field2
1 | ready
2 | ready
1 | in_progress
1 | ready
2 | in_progress


How can i count number of "ready" fields for each field1?
For this example answer must be:

field1 | field2
1 | 2
2 | 1

Answer Source

Simple filter and aggregation will do:

SELECT field1,
    COUNT(*) AS field2
FROM your_table
WHERE field2 = 'ready'
GROUP BY field1;

If you want to get those field1 values where count can be 0:

SELECT field1,
    SUM(field2 = 'ready') as field2
FROM your_table
GROUP BY field1;

SUM(field2 = 'ready') uses the fact that MySQL treats true as 1 and false as 0.