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 )
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter