当我对我的查询字符串进行排名时,应用程序崩溃

App crashes when i and ranking to my query string

"SELECT * FROM " + STUDENT_TABLES;

此代码有效,但我想要排名列,所以我添加了更新到此

  String queryString = "SELECT *,RANK () OVER" + "( " +"ORDER BY " + STUDENT_NAME_COL + " )" +  SP + " FROM " + STUDENT_TABLES ;

它在左括号 ,FROM,GROUP,ORDER.WHERE,COMMA or SEMMICOLON expected, got "(" 和应用程序崩溃;

这是它的看法enter image description here

可能您运行应用程序的设备中的 SQLite 版本低于 3.25.0,因此它不支持 window 功能。

您可以使用相关子查询模拟 RANK()

String queryString = 
    "SELECT s1.*, " + 
    "(SELECT COUNT(*) + 1 FROM " + STUDENT_TABLES + " AS s2 WHERE s2." + STUDENT_NAME_COL + " < s1."  +  STUDENT_NAME_COL + ") AS SP "+
    "FROM " + STUDENT_TABLES + " AS s1";