我尝试在 android 中运行以下原始查询,它似乎不起作用
String query ="SELECT DISTINCT category FROM event";
Cursor cursor = mDb.rawQuery(query, null);
if (cursor != null) {
cursor.moveToFirst();
}
return cursor;
所以我决定在 android 中使用 query() 方法,类似于
Cursor mCursor = mDb.query(EVENT_TABLE, new String[] {KEY_ROWID, KEY_CAT}, null, null,null,null, null)
谁能告诉我如何选择不同的类别来使用 query() 而不是 rawquery,任何帮助将不胜感激!
最佳答案
但你必须记住在 GROUPBY
中发送参数(NOT NULL
发送)。
您必须为 distinct
提供列名。
例子:
Cursor cursor = db.query(true, YOUR_TABLE_NAME, new String[] { COLUMN_NAME_1 ,COLUMN_NAME_2, COLUMN_NAME_3 }, null, null, COLUMN_NAME_2, null, null, null);
true - 不同的 TRUE
COLUMN_NAME_2
- 名称列你有什么是 DISTINCT。
这对我来说很好。
关于android - 在android sqlite中选择不同的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11219361/