update receiving_bill
set lost_ton_deduction = if((quantity - real_quantity - 0.1) > 0, (quantity - real_quantity - 0.1) * 1000, null)
where id in (
select *
from (select id
from receiving_bill
where quantity is not null
and real_quantity is not null) as a);
数据库中不能在同一表中查询的数据作为同一表的更新数据,需要建一个临时表或者两个表分别写一个不同的别名