db-torque-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Seth Milder <mrs...@physics.gmu.edu>
Subject Aggregates
Date Mon, 24 Mar 2003 23:17:44 GMT
Hi everyone,

What is a good way to do aggregates? I saw the thread about count(*), 
but it does not seem to work. This is what I am trying now:

	Criteria c = new Criteria();
	c.addSelectColumn("COUNT(ID)");
	c.addGroupByColumn("ID");
	c.add(AccountTransactionPeer.FOO_ID, getId());

	try {
	    List result = AccountTransactionPeer.doSelect(c);
	    Record rec = (Record) result.get(0);
	    int count = rec.getValue(0).asInt();
	    if (log.isDebugEnabled()) {
		log.debug("getting transaction counts NUM -> " + count);
	    }
	    return count;
	} catch (Exception e) {
	    e.printStackTrace();
	    return -1;
	}

Which produces this exception:

org.apache.torque.TorqueException: Malformed column name in Criteria 
select: 'COUNT(ID)' is not of the form 'table.column'

Anyone know the proper way to do this? Do I have to use 
BasePeer.executeQuery() ?

-- 
Seth Milder
Department of Physics and Astronomy
MS 3f3
George Mason University
Fairfax, VA
http://www.mrseth.org
--
To invent, you need a good imagination and a pile of junk. -- Thomas Edison


Mime
View raw message