Skip to content
Advertisement

SELECT count based on columns value

I have a table like this

What result I want to achieve is something like this

I’ve tried something like this

the result is that I don’t have at least duplicate records in Name column, but I can clearly see with simple select count(*) that the counts in the columns are not right.

First of all I did google some samples, and made the SELECT above.

Advertisement

Answer

I would use SUM() instead. You have a problem with NULL:

Your unused will always be zero because COUNT(NULL) is always zero.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement