Conditions for grouped values, corresponding to an SQL HAVING clause