insert into tdte
SELECT
null,
CONCAT(
n.cym,
SUBSTR( coalesce(m.IDX, 1)+1000,2)
)
FROM (SELECT SUBSTRING( CONCAT(YEAR(NOW()), SUBSTRING( MONTH(NOW())+100,2) ),3) as cym) as n
LEFT JOIN (SELECT SUBSTRING(dte,1,4) ym , MAX(SUBSTRING(dte,5,5)) IDX FROM tdte GROUP BY ym ) m on m.ym=n.cym