I am currently using greenDAO as the ORM for my Android Application. I ran into an issue when trying to execute a GROUPBY clause.
greenDAO does not have API / helper methods for performing groupby clauses, so I decided to use query()
or queryRaw()
methods available for the AbstractDAO class, where I can pass a valid SQL query. BUT, both these methods return a java.util.List, so what confuses me is that how can I get values of column aliases in the result?
Eg,
SELECT COUNT(ID) AS NUMOFRECORDS, NAME FROM PERSONS GROUP BY AGE
My entity will have NAME and AGE fields, but I created a column alias NUMOFRECORDS, which is not part of the Entity.
Appreciate your help!
This is a alternative solution for your question: Include the ORDER BY insize of Where.
Ex:
List<Taxi> list = daoSession.getDaoTaxi().queryBuilder().where(new WhereCondition.StringCondition("1 GROUP BY cant_aciento")).list();
I'm stuck with a similar problem. It seems that greenDao doesn't support GROUP BY querys and it won't change in the future, according to what they said here:
GROUP BY is SQL-ish, so stick to SQL. greenDAO is about entities, where GROUP BY is unsupported.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With