sql >> Base de Datos >  >> RDS >> Mysql

SQL:ACTUALIZAR desde una selección compleja

UPDATE table1 
SET skipbill = 1 
WHERE sqlid IN (
    SELECT DISTINCT t.sqlid 
    FROM (
        SELECT t.*, (@cume := @cume + billsec) AS cume 
        FROM table1 t 
        CROSS JOIN (SELECT @cume := 0) vars 
        ORDER BY calldate
    ) t, table2 sct 
    WHERE t.cume <= sct.bonus_seconds 
          AND t.customer_id = sct.customer_id
);