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


--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to