USE `vn`;

-- Añadir campo en la tabla ticket

ALTER TABLE `vn`.`ticket` 
ADD COLUMN `weight` DECIMAL(10,2) NULL DEFAULT NULL COMMENT 'En caso de informar, se utilizará su valor para calcular el peso de la factura' AFTER `totalWithoutVat`;

-- Actualizar campo con los valores de ticketObservation 

UPDATE 
    vn.ticket t
        JOIN (SELECT t.ticketFk, CAST(t.description AS DECIMAL(10,2))  weight
                FROM vn.ticketObservation t
                    LEFT JOIN vn.observationType ot ON ot.id = t.observationTypeFk 
                WHERE ot.code ='weight' 
                    having weight > 0)sub ON sub.ticketFk = t.id
    SET t.weight = sub.weight;