Fixing conditional count select queries.