DELIMITER $$
CREATE TRIGGER TRIGGER_NAME
BEFORE INSERT ON TABLE_NAME FOR EACH ROW
BEGIN
SET NEW.ORD = (SELECT MAX(COLUNM_NAME)+1 FROM TABLE_NAME WHERE CONDITIONS);
END $$
DELIMITER ;
CREATE TRIGGER TRIGGER_NAME
BEFORE INSERT ON TABLE_NAME FOR EACH ROW
BEGIN
SET NEW.ORD = (SELECT MAX(COLUNM_NAME)+1 FROM TABLE_NAME WHERE CONDITIONS);
END $$
DELIMITER ;