SimplyJaymin
SimplyJaymin

Reputation: 444

GreenDAO groupby clause

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!

Upvotes: 7

Views: 2562

Answers (2)

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

Upvotes: 6

Jofre Mateu
Jofre Mateu

Reputation: 2430

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.

Upvotes: 2

Related Questions