如何使用"分组依据"选项从MEDIA提供商进行查询?

gks*_*ope 8 android android-contentprovider

我是Android的新手.实际上,我想从内容提供商和内容解析器查询媒体提供商的数据.

c = mContent.query(CONTENT_URI,projection,where,null,null); 
Run Code Online (Sandbox Code Playgroud)

我的问题是,我如何使用GROUP BY子句从媒体提供者查询数据如下:

select DISTINCT _id, count(_id), _data FROM aaa_table WHERE _data LIKE "A" OR _data LIKE "B" GROUP BY _id;
Run Code Online (Sandbox Code Playgroud)

我曾尝试设置projectionwhere如下:

 final String[] projection = new String[] {
                "_id", 
                "COUNT ("+ _id +")" ,
                "_data" 
                }; 
Run Code Online (Sandbox Code Playgroud)

并且where:

_data LIKE "A" OR _data LIKE "B"
Run Code Online (Sandbox Code Playgroud)

但是,我找不到如何设置查询选项GROUP BY _id.

请帮我.

小智 9

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); 
Run Code Online (Sandbox Code Playgroud)

referance page = http://zengyan2012.iteye.com/blog/1118963


Pen*_*m10 3

我不确定这是否可能。

我最近在处理类似的问题上遇到了困难,我设法通过将数据插入ContentProvider到临时表中并查询表中的结果来解决问题。

故事是,a 背后的数据ContentProvider可能不是数据库。它可以是 XML、JSON、文件系统等...所以这些没有选项GROUP BY,因此他们将其排除在外。你也不能认为这总是count(_id)有效。