update node set carry = ( select l1.value from enode o,enode l1 where o.id = l1.parent and node.id = o.id and not exists ( select o2.id from enode o2 where o2.parent = o.id and o2.value is null and o2.carry is null) and (select count(*) from enode oo,enode ll1 where oo.id = ll1.parent and o.id = oo.id ) = 1 UNION select l1.value+l2.value from enode o,enode l1,enode l2 where o.id = l1.parent and o.id = l2.parent and o.op = '+' and l1.id < l2.id and node.id = o.id and not exists ( select o2.id from enode o2 where o2.parent = o.id and o2.value is null and o2.carry is null) and (select count(*) from enode oo,enode ll1 where oo.id = ll1.parent and o.id = oo.id ) = 2 UNION select l1.value+l2.value+l3.value from enode o,enode l1,enode l2,enode l3 where o.id = l1.parent and o.id = l2.parent and o.id = l3.parent and o.op = '+' and l1.id < l2.id and l2.id < l3.id and node.id = o.id and not exists ( select o2.id from enode o2 where o2.parent = o.id and o2.value is null and o2.carry is null) and (select count(*) from enode oo,enode ll1 where oo.id = ll1.parent and o.id = oo.id ) = 3 UNION select l1.value-l2.value from enode o,enode l1,enode l2 where o.id = l1.parent and o.id = l2.parent and o.op = '-' and l1.id < l2.id and node.id = o.id and not exists ( select o2.id from enode o2 where o2.parent = o.id and o2.value is null and o2.carry is null) and (select count(*) from enode oo,enode ll1 where oo.id = ll1.parent and o.id = oo.id ) = 2 UNION select l1.value-l2.value-l3.value from enode o,enode l1,enode l2,enode l3 where o.id = l1.parent and o.id = l2.parent and o.id = l3.parent and o.op = '-' and l1.id < l2.id and l2.id < l3.id and node.id = o.id and not exists ( select o2.id from enode o2 where o2.parent = o.id and o2.value is null and o2.carry is null) and (select count(*) from enode oo,enode ll1 where oo.id = ll1.parent and o.id = oo.id ) = 3 UNION select l1.value*l2.value from enode o,enode l1,enode l2 where o.id = l1.parent and o.id = l2.parent and o.op = '*' and l1.id < l2.id and node.id = o.id and not exists ( select o2.id from enode o2 where o2.parent = o.id and o2.value is null and o2.carry is null) and (select count(*) from enode oo,enode ll1 where oo.id = ll1.parent and o.id = oo.id ) = 2 UNION select l1.value*l2.value*l3.value from enode o,enode l1,enode l2,enode l3 where o.id = l1.parent and o.id = l2.parent and o.id = l3.parent and o.op = '*' and l1.id < l2.id and l2.id < l3.id and node.id = o.id and not exists ( select o2.id from enode o2 where o2.parent = o.id and o2.value is null and o2.carry is null) and (select count(*) from enode oo,enode ll1 where oo.id = ll1.parent and o.id = oo.id ) = 3 ) where carry is null ;