Let’s say I have a table with two columns, a client_id and a boolean.
There are multiple data entries for a given client_id, each of which may or may not have the boolean value set to true.
I need a query that will return only the client_ids that have NO ROWS with the boolean set to true, and I need it grouped by client_id.
I’m sure this is simple, it just escapes me right now.
Use the
HAVINGclause to filter the groups:Note that
SUM(boolean)works in MySQL because it does not have true boolean types; in other RDBMS you would either have to use a different aggregate function or else test the boolean and return a result that can be used inSUM():