Naroju Naroju - 4 months ago 142
Android Question

How to use GROUP BY in GreenDao

I have found few questions related to this issue in SO, but did not help me much.I want to construct a query in Android using GreenDao library, query should grab all the rows containing particular phonenumber in descending order of datetime and I also want to group them by group name.
My query:

List<activity> activities = activityDao.queryBuilder().where(Properties.Contact_number.eq(phonenumber)).orderDesc(Properties.Date_time).build().list();

How to include GROUP BY in above query so as to group the rows by
(I have group_name as column in table)?

I did not find any GROUP BY method in GreenDao,not sure if I am correct.


GROUP BY is not supported by GreenDao.
You can use this trick :

where(new WhereCondition.StringCondition(Properties.Contact_number.eq(phonenumber) + "GROUP BY group_name")).orderDesc(Properties.Date_time).build().list();

It let you build your where clause using String.