https://dev.mysql.com/doc/refman/8.0/en/insert-on-duplicate.html

INSERT INTO t1 SET a=1,b=2,c=3 AS new
  ON DUPLICATE KEY UPDATE c = new.a+new.b;