I test sql and it works fine in Sqlite Spy:
select ifnull(_name, _number) as identifer, count(_id) as amount from call group by identifer
And I wanna use it in ContentConsolver but it can’t work with “group by”:
String[] projections = new String[] { "ifnull(name, number) as identifer", "count(_id) as amount" };
String group = "identifer";
//String selection = ") GROUP BY (" + group;
Cursor cursor = getContentResolver().query(CallLog.Calls.CONTENT_URI, projections, null, null, null /*!group*/ );
What should I do?
@njzk2 did the trick by using HashSet: Group By in ContentResolver in Ice Cream Sandwich, But it didn’t work with count() if you want sum.
I think the best solution is to make a copy of CallLog Database, then you can use rawQuery() or whatever you want (maybe it is a waste of performance).