[rules-users] Disting and group by
Wolfgang Laun
wolfgang.laun at gmail.com
Wed Aug 11 04:01:59 EDT 2010
With an additional class PurchaseSum
List<Customer> customers;
... purchaseDate;
... custNo;
... sum;
}
you can write these rules;
rule "insert PurchaseSum"
when
Customer( $pd : purchaseDate, $cn : custNo )
not( PurchaseSum( purchaseDate == $pd, custNo == $cn ) )
then
insert( new PurchaseSum( $cn, $pd );
end
rule "accumulate amounts"
when
$cu : Customer( $pd : purchaseDate, $cn : custNo, $am : amount )
$ps : PurchaseSum( purchaseDate == $pd, custNo == $cn, customers not
contains $cu )
then
modify( $ps ){
setSum( $ps.getSum() + amount ),
setCustomers( $ps.getCustomers().add( $cu )
}
end
rule "show amounts > X"
salience -100
when
$ps : PurchaseSum( amount > X )
thne
System.out.println( $ps... );
retract( $ps );
end
rule "clean up"
salience -101
when
$ps : PurchaseSum()
thne
retract( $ps );
end
On 10 August 2010 20:03, vijrams <mailrvijay at gmail.com> wrote:
>
> Hi
>
> i have an object customer (purchaseDate, CustNo, Amount)
>
> i need to find the customers who purchased more than X amount in each date)
> ie group by customer then group by date and then sum of amount
>
>
> how do you write a rule for this
>
> thanks
> Vijay
> --
> View this message in context: http://drools-java-rules-engine.46999.n3.nabble.com/Disting-and-group-by-tp1076615p1076615.html
> Sent from the Drools - User mailing list archive at Nabble.com.
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>
More information about the rules-users
mailing list