<div><br></div>   &quot;Group by&quot; 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 &quot;group by&quot; customer:<div><br></div><div>
when</div><div>   Customer(...)</div><div>   ...</div><div>then</div><div><br></div><div>    &quot;Distinct&quot; is a bit problematic, as we have no explicit distinct functionality (I have an open ticket for that: <a href="https://jira.jboss.org/browse/JBRULES-2640">https://jira.jboss.org/browse/JBRULES-2640</a>) but in some cases you can use collectSet for similar results.</div>
<div><br></div><div>     In your case, you can go with Wolfgang&#39;s suggestion, or using accumulate:</div><div><br></div><div>declare ReportForDate</div><div>     custNo : String </div><div>     date : Date</div><div>end</div>
<div><br></div><div>rule &quot;insert report dates&quot;</div><div>    salience 10</div><div>    dialect &quot;mvel&quot;</div><div>when</div><div>    Customer( $pd : purchaseDate, $custNo : custNo )</div><div>    not( ReportForDate( custNo == $custNo, date == $pd ) )</div>
<div>then</div><div>    with( $r = new ReportDate() ) {</div><div>        custNo = $custNo,</div><div>        date == $pd</div><div>    }</div><div>    insert( $r );</div><div>end</div><div><br></div><div>rule &quot;customers that purchased more than 100 on a given date&quot;</div>
<div>when</div><div>    ReportDate( $pd: date, $cn : custNo )</div><div>    Number( $total : doubleValue &gt; 100 ) from accumulate(</div><div>         Customer( $custNo == $cn, purchaseDate == $pd, $am : amount ),</div><div>
         sum( $am ) )</div><div>then</div><div>    // do something as the customer $cn purchased $total on $pd</div><div>end</div><div><br></div><div>    Edson<br><br><div class="gmail_quote">2010/8/10 vijrams <span dir="ltr">&lt;<a href="mailto:mailrvijay@gmail.com">mailrvijay@gmail.com</a>&gt;</span><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><br>
Hi<br>
<br>
i have an object customer (purchaseDate, CustNo, Amount)<br>
<br>
i need to find the customers who purchased more than X amount in each date)<br>
ie group by customer then group by date and then sum of amount<br>
<br>
<br>
how do you write a rule for this<br>
<br>
thanks<br>
Vijay<br>
<font color="#888888">--<br>
View this message in context: <a href="http://drools-java-rules-engine.46999.n3.nabble.com/Disting-and-group-by-tp1076615p1076615.html" target="_blank">http://drools-java-rules-engine.46999.n3.nabble.com/Disting-and-group-by-tp1076615p1076615.html</a><br>

Sent from the Drools - User mailing list archive at Nabble.com.<br>
_______________________________________________<br>
rules-users mailing list<br>
<a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
</font></blockquote></div><br><br clear="all"><br>-- <br>  Edson Tirelli<br>  JBoss Drools Core Development<br>  JBoss by Red Hat @ <a href="http://www.jboss.com">www.jboss.com</a><br>
</div>