Untitled
UPDATE agents set quota = ( COALESCE((select sum(qty) from orders where agent_id = agents.id and transaction_type = '1' ),0) - COALESCE((select count(id) from advertises where agent_id = agents.id),0) ) where id is not null;
Leave a Comment
UPDATE agents set quota = ( COALESCE((select sum(qty) from orders where agent_id = agents.id and transaction_type = '1' ),0) - COALESCE((select count(id) from advertises where agent_id = agents.id),0) ) where id is not null;