cpeters5
asked on
MySQL syntax for count
I want to count records in a table that satisfying a condition. But I also want to output a zero if there is no such record. For example
Tab=
id col1 col2
1 a 5
2 b 0
3 c 2
4 a 12
The query
select col1, count(*) from tab where col2 > 0 group by 1;
would return
a 2
c 1
I want the put put to also show
b 0
How do I do this?
pax
Tab=
id col1 col2
1 a 5
2 b 0
3 c 2
4 a 12
The query
select col1, count(*) from tab where col2 > 0 group by 1;
would return
a 2
c 1
I want the put put to also show
b 0
How do I do this?
pax
ASKER
Perfect!
Thanks ralmada
Thanks ralmada
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
from tab group by col1