【问题标题】:How to limit in sqllite query?如何限制sqlite查询?
【发布时间】:2018-06-14 11:42:29
【问题描述】:
 public String readQuestion(int i)//Used to read the data from the Des.db file where id is given and we choose id randomly
{
    String Ans = "";//string that contains the required field  note that Ans is just a local string not related to Answer or Option...
    Cursor c = sqlite.rawQuery("SELECT " + Question + " FROM " + Table_name + " LIMIT " + 5 + " WHERE " + uid + " = " + i + "", null);//cursor to that query
    if (c.moveToFirst())
        Ans = c.getString(0);
    else
        Ans = "";
    return Ans;
}

我想在这个查询中添加一个限制。像 LIMIT 10。

【问题讨论】:

  • 请不要编辑您的旧问题来提出一个全新的问题,因为以前的答案无效!相反,欢迎您提出new question,这将吸引新的答案

标签: android sql sqlite


【解决方案1】:

你已经接近了。 LIMIT 关键字需要位于查询的结尾。您目前拥有的位置:

"SELECT " + Question + 
" FROM " + Table_name + 
" LIMIT " + 5 + 
" WHERE " + uid + " = " + i + ""

这应该是

"SELECT " + Question + 
" FROM " + Table_name + + 
" WHERE " + uid + " = " + i +
" LIMIT " + 5 + ""

【讨论】:

    【解决方案2】:
    Cursor c = sqlite.rawQuery("SELECT " + Question + " FROM " + Table_name + " WHERE " + uid + " = " + i + " LIMIT 5 ", null);
    

    限制在查询的末尾。您应该查看链接以获取详细信息。 sqlite limit statement

    【讨论】:

    • Cursor c = sqlite.rawQuery("SELECT " + Question + " FROM " + Table_name + " WHERE " + uid + " = " + i + " LIMIT 5 " , null);//cursor到那个查询什么都没有发生。
    【解决方案3】:

    请考虑零钱。

    Cursor c = sqlite.rawQuery("SELECT " + Question + " FROM " + Table_name  
               + " WHERE  " + uid + " = " + i  + " LIMIT " + "5", null);
    

    【讨论】:

      猜你喜欢
      • 2012-02-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-07-23
      • 2018-09-16
      • 1970-01-01
      相关资源
      最近更新 更多