I am using a select count distinct to count the number of records in a column. However, I only want to count the records where the value of a different column is 1.
So my table looks a bit like this:
Name——Type
abc———1
def———-2
ghi———-2
jkl———–1
mno——–1
and I want the query only to count abc, jkl and mno and thus return ‘3’.
I wasn’t able to do this with the CASE function, because this only seems to work with conditions in the same column.
EDIT: Sorry, I should have added, I want to make a query that counts both types.
So the result should look more like:
1—3
2—2
If you want to return the counts by type:
You should avoid using keywords like type as column names – you can avoid a lot of square brackets if you use a more specific, non-reserved word.