我正在尝试使用Order by NEWID()
获取随机顺序,如下所示:
public Cursor getSpecialList(String bloodCategory) {
SQLiteDatabase db = this.getReadableDatabase();
Cursor cur = db.rawQuery("SELECT " + colName + " ," +
"" + colFather + " ," +
"" + colFamily + " ,"+
"" + colPhone + " from " + ListInfoTable +
" WHERE " + colBloodCategory + "='" + bloodCategory + "'" +
" order by NEWID() ", new String[]{});
return cur;
}
SQLite 日志给出了以下错误:
没有这样的功能NEWID
答案 0 :(得分:2)
您可以将以下代码用于随机数据:
public Cursor getSpecialList(String bloodCategory )
{
SQLiteDatabase db=this.getReadableDatabase();
Cursor cur=db.rawQuery("SELECT "+colName+" ,"+
""+colFather+" ,"+
""+colFamily+" ,"+
""+colPhone+" from "+ListInfoTable+
" WHERE "+colBloodCategory+"='"+bloodCategory+"'"+
" ORDER BY RANDOM() ",new String[] {});
return cur;
}