Mysql
 sql >> Datenbank >  >> RDS >> Mysql

SQL:UPDATE von einer komplexen Auswahl

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
);