我开发这个解决方案,如果有其他更好的解决方案请分享。
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;
1条答案
按热度按时间gfttwv5a1#
它可以一次完成
INSERT
查询。我还简化了子查询
变成正义
如果
momento
是一个DATETIME
,SUBSTRING(momento, 1, 10)
更恰当的做法是DATE(momento)
.