I'm a newbie to Android. Actually, I want to query data from Media provider with Content provider & content resolver.
c = mContent.query(CONTENT_URI,projection,where,null,null);
My question is, how can I query data from media provider as below using a GROUP BY
clause:
select DISTINCT _id, count(_id), _data FROM aaa_table WHERE _data LIKE "A" OR _data LIKE "B" GROUP BY _id;
I have tried setting projection
and where
as follows:
final String[] projection = new String[] {
"_id",
"COUNT ("+ _id +")" ,
"_data"
};
and where
:
_data LIKE "A" OR _data LIKE "B"
but, I couldn't find how to set the query option GROUP BY _id
.
Please help me.
where = "_data LIKE 'A' OR _data LIKE 'B'";
where += ") GROUP BY (_id"; // note the char ')' and '(', the ContentResover will completed for U
c = mContent.query(CONTENT_URI,projection,where,null,null);
referance page = http://zengyan2012.iteye.com/blog/1118963
You can't from a ContentProvider
. Now, if you're writing your ContentProvider
you could implement it. Inside your content provider you'd have to use a SQLiteQueryBuilder
class which has a query()
method that takes a GROUP BY
string.
http://developer.android.com/reference/android/database/sqlite/SQLiteQueryBuilder.html
This class also has a setDistinct(true)
method that sets the query as DISTINCT, as you indicated you require in your SQL statement.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With