もくじ
NOT (A or B) = (NOT A) and (NOT B)
抽象例
SELECT * FROM table WHERE NOT (A or B); 同じ SELECT * FROM table WHERE (NOT A) and (NOT B);
具体例
HAVING NOT ( COUNT(DISTINCT a.id) > 1 OR COUNT(DISTINCT b.id) > 1 )
リファクタ
HAVING COUNT(DISTINCT a.id) <= 1 AND COUNT(DISTINCT b.id) <= 1
NOT (A and B) = (NOT A) or (NOT B)
抽象例
SELECT * FROM table WHERE NOT (A and B); SELECT * FROM table WHERE (NOT A) or (NOT B);
具体例
HAVING NOT ( COUNT(DISTINCT a.id) > 1 AND COUNT(DISTINCT b.id) > 1 )
リファクタ
HAVING COUNT(DISTINCT a.id) <= 1 OR COUNT(DISTINCT b.id) <= 1