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