7

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!

SimplyJaymin
  • 444
  • 8
  • 17

2 Answers2

6

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();

ketan
  • 19,129
  • 42
  • 60
  • 98
2

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.

Jofre Mateu
  • 2,390
  • 15
  • 26