简体   繁体   中英

MySQL trigger error doesn't work because it needs a value from another table column

I'm new to the php mysql developpement, I want to make a trigger to be launched after I insert a row in the evolution table. The trigger must take a value ( prixMisDaccord ) from another table ( inscription ) and reduce it value from the evolution column prixAPaye .

Here is what I tried and what I found on Stack Overflow:

DELIMITER $$
CREATE TRIGGER trg_rap
BEFORE INSERT ON evolution FOR EACH ROW
BEGIN
       DECLARE pmd float;
       -- Check BookingRequest table
       SELECT prixMisDaccord
       INTO @pmd
       FROM inscription
       WHERE inscription.idETD= 1;

    
           
           SET NEW.resteAPaye = @pmd-NEW.prixPaye
           WHERE idETD = 1;
        
END;
$$
DELIMITER `;

'i have a probleme from this line SELECT' - Is not the error I get, I do get an error on the set statement because you cannot apply a where clause to a set..There are other problems with your code and you don't seem to know the difference between user defined variables and declared variables see - How to declare a variable in MySQL? and temporary tables..so @pmd-NEW.prixPaye is just nonsense.

If you want more help read https://stackoverflow.com/help/how-to-ask and provide table definitions,sample data and desired outcome all as text in the question.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM