How can I group by on a field which has NULL values?
From Aggregate Functions in SQLite
The count(X) function returns a count of the number of times that X is not NULL in a group. The count(*) function (with no arguments) returns the total number of rows in the group.
So, the COUNT
function does not count NULL
so use COUNT(*)
instead of COUNT(y)
.
SELECT y, COUNT(*) AS COUNTFROM mytableGROUP BY y
Or you can also use COUNT(x)
like this one.
SELECT y, COUNT(x) AS COUNTFROM mytableGROUP BY y