db-torque-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Eric Emminger <e...@ericemminger.com>
Subject Re: Aggregate
Date Fri, 16 May 2003 21:38:38 GMT
Carl

Carl Fyffe wrote:
> Hello!
> I am new to the list but I have searched all over the net (google,
> mail-archive, etc) for how to do aggregates with Torque. Basically I
> want to do:
> 
> select category_name, avg(quantity) from stock group by category_name
> 
> Am I forced to use sql in this instance, or am I missing a feature that
> is documented somewhere?
> 
> What would the java for this look like?

Try this.

Criteria crit = new Criteria();
crit.addSelectColumn(StockPeer.CATEGORY_NAME);
crit.add(StockPeer.QUANTITY, ((Object) "avg(" + StockPeer.QUANTITY + 
")"), Criteria.CUSTOM);
crit.addGroupByColumn(StockPeer.CATEGORY_NAME);
List records = StockPeer.doSelectVillageRecords(crit);


Now you'll have to play with the Village API. Have fun!

Eric


Mime
View raw message