You are viewing a plain text version of this content. The canonical link for it is here.
Posted to torque-user@db.apache.org by Carl Fyffe <ca...@sixty4bit.com> on 2003/05/16 07:11:40 UTC
Aggregate
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?
Carl
Re: Aggregate
Posted by Eric Emminger <er...@ericemminger.com>.
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