From aggregate functions in SQLite
The count (X) function returns a counter for the number of times that X is not NULL in the group. The count (*) function (without arguments) returns the total number of rows in the group.
So, the COUNT function does not take NULL into account, so use COUNT(*) instead of COUNT(y) .
SELECT y, COUNT(*) AS COUNT FROM mytable GROUP BY y
Or you can also use COUNT(x) , like this one.
SELECT y, COUNT(x) AS COUNT FROM mytable GROUP BY y
source share