SELECT customers.id, n.note_category_id, n.created FROM `customers` INNER JOIN notes n ON customers.id=n.customer_id
WHERE n.created >= '2021-1-1' AND '2021-10-30' >= n.created
AND (n.note_category_id = 2 OR n.note_category_id = 5)
AND customers.id in (
    				SELECT customers.id FROM `customers` INNER JOIN notes n ON customers.id=n.customer_id
                    WHERE n.created >= '2021-1-1' AND '2021-10-30' >= n.created
                    AND (n.note_category_id = 2 OR n.note_category_id = 5)
                    GROUP BY customers.id
                    HAVING (sum(n.note_category_id) % 5 = 2) AND sum(n.note_category_id) > 5
					)