INSERT INTO alerte_code_reduction(alerte_code_reduction_code_reduction_id)
SELECT cr.code_reduction_id
FROM code_reduction cr
INNER JOIN code_reduction_vote crv ON crv.code_reduction_vote_code_reduction = cr.code_reduction_id
LEFT JOIN alerte_code_reduction a ON a.alerte_code_reduction_code_reduction_id = cr.code_reduction_id AND a.alerte_code_reduction_date_alerte > date_sub(now(), INTERVAL 7 DAY)
WHERE crv.code_reduction_vote_valeur = 0
AND cr.code_reduction_est_visible = 1
AND cr.code_reduction_est_supprime = 0
AND a.alerte_code_reduction_envoye IS NULL
GROUP BY cr.code_reduction_id
HAVING COUNT(*) > 4;
