Zabrakło warunku dla klienta w podzapytaniu: AND NOT EXISTS (SELECT id FROM customerassignments ca WHERE ca.customerid = c.id AND ca.customergroupid IN (15,4)).