A
SELECT dates.user_id FROM dates
LEFT JOIN pays ON pays.user_id = dates.user_id
WHERE pays.id IS NULL
GROUP BY dates.user_id
HAVING COUNT(dates.user_id) IN (7,8)
We take all the records from the dates, pays with pay, make the condition that no payment has been made, group the user_id and see that the user matches the condition that he has seven or eight sessions.You asked about the number of visits in the second month, while the simplest thing you've come up with, that's how it worked out, of course, I think it's cool, but okay. Choose all the dates, Joyim pays, grouped by user_id, see if the bulb on different dates of the visits is equal to 7*col-wheel or 8*col-to-pay, at least 1, the user enters the interval and can be warned. Pays must have a unique identifier (id), dates must necessarily have a date of visit (date).SELECT dates.user_id, COUNT(DISTINCT pays.id)+1 pcount FROM dates
LEFT JOIN pays ON pays.user_id = dates.user_id
GROUP BY dates.user_id
HAVING COUNT(DISTINCT dates.date) IN (7pcount, 8pcount)
How shorter and more effective to write the second one didn't come to mind yet.