I have a table like this:
id  | module_id | answered 
 1       4           3
 2       4           1
 3       4          NULL
 4       5          NULL 
 5       5           1
I need to calculate the number of the rows for each module_id and the number of rows where answered isn't NULL.
so I need the result
module_id  | row_count  |  answered
    4            3            2
    5            2            1
So far I have
SELECT module_id, COUNT(*) as row_count FROM table GROUP BY module_id
but I have no idea how to do the answered column. Any ideas?
 COUNT(answered)
will count the non-null values in that particular column.
That's why COUNT(*) is a lot faster than COUNT(some-column).
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