Project(Join(Project(Extend(Extend(Extend(Extend(Extend(AggregationJoin(Aggregation(??agg1: ?pid, SAMPLE, {}, G1=Group((?pid, ?cond), Project(Join(ToMultiSet({{(?pid, )}, {(?pid, )}, {(?pid, )}, {(?pid, )}, {(?pid, )}}), Extend(Extend(BGP( ?oid ?pid . ?oid ?price . ?oid ?cond), ?oldIncrement, if((?cond = 1), 0, 1) ), ?newIncrement, if((?cond = 1), 1, 0) )), {?pid, ?oid, ?newIncrement, ?oldIncrement, ?price, ?cond}))), Aggregation(??agg2: ?oid, SAMPLE, {}, G1), Aggregation(??agg3: ?price, MIN, {}, G1), Aggregation(??agg4: ?newIncrement, SUM, {}, G1), Aggregation(??agg5: ?oldIncrement, SUM, {}, G1)), ?pid, ??agg1), ?oid1, ??agg2), ?minPrice, ??agg3), ?newOff, ??agg4), ?usedOff, ??agg5), {?pid, ?oid1, ?minPrice, ?newOff, ?usedOff}), BGP( ?pid ?title)), {?minPrice, ?newOff, ?oid1, ?pid, ?title, ?usedOff})