排序时出现MySQL触发变量错误

时间:2019-04-30 18:15:21

标签: mysql triggers

我有下一个无法解决的代码。

行Set @Numero = ...返回错误

$query = $pdo->prepare("SELECT count(*) FROM table WHERE x = 1556555454");

我尝试过

  Begin
Declare @Numero INT;
SET @Numero= SELECT id from visita where cliente_id=OLD.cliente_Id order by id desc limit 1;


INSERT INTO HistoricoMaquina
    SET
    Precio=OLD.Precio,
    fecha = NOW(),
    Visita_Id=@Numero;
End;

select @Numero=Id from visita where cliente_id=1 order by id desc limit 1;

但是它们都不起作用,有任何想法吗?

1 个答案:

答案 0 :(得分:1)

如果您的“选择”查询给出了答案,这将起作用

INSERT INTO HistoricoMaquina (Precio,fecha,Visita_Id) 
 SELECT OLD.Precio, NOw(),id from visita where cliente_id=OLD.cliente_Id order by id desc limit 1;