我想从 Android 中的应用程序 sqlite 数据库中提取随机行。我知道,使用 sqlite,您可以选择随机行:
SELECT * FROM table ORDER BY RANDOM() LIMIT 1;
在应用程序中,我有这样的东西
return mDb.query(TABLE, new String[] {"col1", "col2"}, null, null, null, null, "Random()", "2");
这是为了在表 TABLE 中提取两个随机行。但它不断返回相同的行。声明有什么问题?
谢谢
最佳答案
试试这个
Cursor cursor = this.db.query("YourTable Order BY RANDOM() LIMIT 1",
new String[] { "*" }, null, null, null, null, null);
关于android - sqlite 和 Android sdk 中的 Random(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8369767/