i have a mysql products table like that;
http://www.sqlfiddle.com/#!9/56ac8e/2
when each line is added, I want it to compare with the latest price of the same coded product. if it is cheaper than the latest price, I want it to add rows to another table in the following way.
discount table is ;
http://www.sqlfiddle.com/#!9/c2227d/1
i changed the codes in the form of the link below, but it didn't work. Compare rows in same table in mysql
CREATE DEFINER = CURRENT_USER TRIGGER `database`.`products_AFTER_INSERT` AFTER INSERT ON `products` FOR EACH ROW
BEGIN
WHERE NEW.product_id = OLD.product_id
IF NEW.price < OLD.price
THEN
INSERT INTO discount
(
id (auto) ,
product_id,
name ,
old.price ,
new.price ,
discount ((old.price / new.price )/10)
);
END IF;
END$$
can you help me in this regard ?