Hello everyone, I cannot figure out what I am doing wrong here. My goal is to show all cells in a housing unit where 3 or more inmates are housed. When I run the sql statement below I get cells with 2 inmates and cells with 3 inmate. I only want to see cells with 3 inmates in them, please help if you are able thank you for taking time.
SELECT OFFENDER, FACILITY, BLOCK, CELL, BED, MOVEIN, MOVEOUT, STAY
FROM pps_housingchanges AS H
WHERE (MOVEIN < '7/2/2009 00:00') AND (MOVEOUT > '7/2/2009 00:00' OR
MOVEOUT IS NULL) AND (FACILITY = 'HOC') AND (BLOCK = 'D2BLK') AND
((SELECT COUNT(OFFENDER) AS Expr1
FROM pps_housingchanges
WHERE (MOVEIN < '7/2/2009 00:00') AND (MOVEOUT > '7/2/2009 00:00' OR
MOVEOUT IS NULL)) > 2)
ORDER BY BLOCK, CELL, BED
SELECT OFFENDER, FACILITY, BLOCK, CELL, BED, MOVEIN, MOVEOUT, STAY
FROM pps_housingchanges AS H
WHERE (MOVEIN < '7/2/2009 00:00') AND (MOVEOUT > '7/2/2009 00:00' OR
MOVEOUT IS NULL) AND (FACILITY = 'HOC') AND (BLOCK = 'D2BLK') AND
((SELECT COUNT(OFFENDER) AS Expr1
FROM pps_housingchanges
WHERE (MOVEIN < '7/2/2009 00:00') AND (MOVEOUT > '7/2/2009 00:00' OR
MOVEOUT IS NULL)) > 2)
ORDER BY BLOCK, CELL, BED