0

I am running a query on a view entity which results in some datasets. The problem is I want to do a group-by on the resultant dataset. To make it clear, the simplified version of my query is something similar to:

SELECT OBJECT1, OBJECT2 FROM MY_TABLE WHERE OBJECT3=? AND OBJECT4=? GROUP BY OBJECT1.  

Here, MY_TABLE is an existing view entity in the system and I am applying some filters to fetch the relevant data. The code looks something like:

if(UtilValidate.isNotEmpty(productId)) {
              andExprs.add(EntityCondition.makeCondition("productId", productId));
            }
            if( UtilValidate.isNotEmpty(statusId) && !statusId.equalsIgnoreCase("All")) {
              andExprs.add(EntityCondition.makeCondition("statusId", statusId));
            }
            andExprs.add(EntityCondition.makeCondition(
                        EntityFunction.UPPER_FIELD("issueDate"),
                        EntityOperator.BETWEEN,
                        criteria));
            andExprsList = EntityCondition.makeCondition(andExprs,
                    EntityOperator.AND);
            quoteList = delegator
            .findListIteratorByCondition(dynamicViewForQuotesByProduct,  andExprsList,
                    null, fieldsToSelectForQuotesByProduct, null, null);  

My question is how can I group-by the result returned by this findListIteratorByCondition. Thanks in advance!

newbie
  • 663
  • 2
  • 6
  • 19

2 Answers2

1

While preparing the dynamic view entity (dynamicViewForQuotesByProduct in your case) you can specify group by in "addAlias", the third parameter in "findListIteratorByCondition" is havingEntityCondition i.e actually the EntityCondition object that specifies how to constrain this query after any groupings are done (if this is a view entity with group-by aliases) internally checks for the view entity that you pass and this how you can group-by your query.

-1

Pass value of groupBy parameter as true in addAlias() method.

johnnyRose
  • 7,310
  • 17
  • 40
  • 61