im sure this is easy but im having a block I am trying to write some sql against a single table that has (simplified for example)
RunName, Result
foo, pass
foo, pass
foo, fail
foo, pass
boo, pass
boo, fail
boo, fail
soo, pass
I was a query that will return a count of pass or fail for each name
something like for fail
foo, 1
boo, 2
soo, 0
and for pass
foo, 3
boo, 1
soo, 1
Normally you’d do a simple COUNT and GROUP BY RunName, but that will not show “zero results” like soo’s fails.
This should work even for zero results (on MySQL)
Demo here.
Edit: As Aaron points out, that only works on MySQL, this works on SQL Server also;
Demo here.
Edit2: As Marcus points out, it’s may not be a very index friendly way of doing the query, so if you have a primary key you may be better off doing a self join with a count/group to get the correct result;
Demo here.