lundi 9 juillet 2018

Conditional MySQL INSERT

I develop this solution, if any else have a better solution please share.

SET @num = (SELECT count(distinct(detalle)) as 'distintos'
FROM
(SELECT detalle, SUBSTRING(momento, 1, 10) as momento FROM t2
where detalle in ('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I')) AS T1
where momento like (Select SUBSTRING(momento, 1, 10) as momento from t2 order by momento desc limit 1));

INSERT INTO `t2`.`log_reportes` (`accion`, `detalle`)
SELECT 'REVISION AUTOMATICA', 'ERROR' FROM DUAL
WHERE @num = 6;

INSERT INTO `t2`.`log_reportes` (`accion`, `detalle`)
SELECT 'REVISION AUTOMATICA', 'OK' FROM DUAL
WHERE @num = 7;

Aucun commentaire:

Enregistrer un commentaire