Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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!

like image 606
SimplyJaymin Avatar asked Jan 12 '15 16:01

SimplyJaymin


2 Answers

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

like image 161
Adrian Arencibia Herrera Avatar answered Oct 19 '22 04:10

Adrian Arencibia Herrera


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.

like image 30
Jofre Mateu Avatar answered Oct 19 '22 04:10

Jofre Mateu