Update the info in red.

SET @start = '2022-01-01', @finish = '2022-12-31'; 

INSERT INTO cycles (site_code, cycle_type, cycle_iteration, start_date, end_date, mailing_sent, last_update_user)

SELECT cyc.site_code, cyc.cycle_type, cyc.cycle_iteration, cyc.start_date, cyc.end_date, cyc.mailing_set, cyc.last_update_user
FROM (
SELECT site_code, 'Renewal' as cycle_type, MAX(cycle_iteration) + 1 AS cycle_iteration , @start AS start_date, @finish AS end_date, 1 as mailing_set, 'generated' AS last_update_user
FROM cycles
WHERE site_code in (
SELECT site_code
FROM solutio.sites
WHERE active = 1
AND client_model = 'Ads'
)
AND cycle_type = 'Renewal'
GROUP BY site_code

UNION

SELECT site_code, 'Renewal' as cycle_type, 1 AS cycle_iteration, @start AS start_date, @finish AS end_date, 1 as mailing_set, 'generated' AS last_update_user
FROM sites
WHERE active = 1
AND client_model = 'Ads'
AND site_code NOT IN (
SELECT site_code
FROM cycles
WHERE cycle_type = 'Renewal'
)
AND site_code IN (
SELECT site_code
FROM cycles
WHERE cycle_type = 'New'
)

) cyc
WHERE (cyc.site_code, BINARY cyc.cycle_type, cyc.start_date) NOT IN (
SELECT site_code, BINARY cycle_type, start_date
FROM cycles)