SELECT COUNT(*) as Count, IF(sch.HomeTeamID = 34,true,false) AS Hawaii
FROM schedule sch
JOIN schools s ON s.ID = 83
WHERE (sch.HomeTeamID = 83 OR sch.AwayTeamID = 83)
AND sch.SeasonID = 4
I’m trying to use count() to simplify my result but also include a field that represents wether any of the results’ specific column contained a certain value. Is this possible? I’d basically like a row response with all the info I need.
If you are trying to count how many times the home team was 34, do this:
Incidentally, the terse summing of a condition works in mysql only, because in mysql true is 1 and false is 0, so sum(condition) counts how many times it was true (other databases requires the use of a case statement)