"Group by" is implicit in rules, just by writing patterns in order. So, if you write a rule that starts with Customer(), it will automatically do a "group by" customer:

when
   Customer(...)
   ...
then

    "Distinct" is a bit problematic, as we have no explicit distinct functionality (I have an open ticket for that: https://jira.jboss.org/browse/JBRULES-2640) but in some cases you can use collectSet for similar results.

     In your case, you can go with Wolfgang's suggestion, or using accumulate:

declare ReportForDate
     custNo : String 
     date : Date
end

rule "insert report dates"
    salience 10
    dialect "mvel"
when
    Customer( $pd : purchaseDate, $custNo : custNo )
    not( ReportForDate( custNo == $custNo, date == $pd ) )
then
    with( $r = new ReportDate() ) {
        custNo = $custNo,
        date == $pd
    }
    insert( $r );
end

rule "customers that purchased more than 100 on a given date"
when
    ReportDate( $pd: date, $cn : custNo )
    Number( $total : doubleValue > 100 ) from accumulate(
         Customer( $custNo == $cn, purchaseDate == $pd, $am : amount ),
         sum( $am ) )
then
    // do something as the customer $cn purchased $total on $pd
end

    Edson

2010/8/10 vijrams <mailrvijay@gmail.com>

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@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users



--
  Edson Tirelli
  JBoss Drools Core Development
  JBoss by Red Hat @ www.jboss.com