SELECT
users.nom,
users.email,
users.id,
s.label AS 'Activité'
FROM users
INNER JOIN services_users su ON su.id_user = users.id
INNER JOIN services s ON s.id = su.id_service
WHERE (
s.label = "Cotisation " || strftime('%Y', DATE('now', '-1 year'))
OR
s.label = "Cotisation " || strftime('%Y', DATE('now', '-2 year'))
OR
s.label = "Cotisation " || strftime('%Y', DATE('now', '-3 year'))
)
AND users.id NOT IN (
SELECT users.id
FROM users
INNER JOIN services_users su ON su.id_user = users.id
INNER JOIN services s ON s.id = su.id_service
WHERE s.label = "Cotisation " || strftime('%Y', DATE())
)
GROUP BY users.id
ORDER BY users.nom
LIMIT 1000
;