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