SQL查询问题

时间:2015-08-07 17:19:18

标签: android sqlite

从早上开始努力让SQL查询正常工作。我试图检查特定字段是否只有前500(记录1到记录500)记录的0值。

我尝试了以下内容:

SZArrayHelper

这给了我以下错误:

SELECT * FROM UnMappText  WHERE updateTime = '0' desc LIMIT 0, 500;

所以我尝试了以下方式:

Process: com.ylg.dbaccess, PID: 18738
    android.database.sqlite.SQLiteException: near "desc": syntax error (code 1): , while compiling: SELECT * FROM UnMappText WHERE updateTime = '0' desc LIMIT 0, 500
            at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
            at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:889)
            at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:500)
            at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
            at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58)
            at android.database.sqlite.SQLiteQuery.<init>(SQLiteQuery.java:37)
            at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:44)
            at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1316)
            at android.database.sqlite.SQLiteDatabase.rawQuery(SQLiteDatabase.java:1255)
            at com.ylg.dbaccess.UnMappText (DBValue.java:3312)
            at android.os.Handler.handleCallback(Handler.java:739)
            at android.os.Handler.dispatchMessage(Handler.java:95)
            at android.os.Looper.loop(Looper.java:135)
            at android.app.ActivityThread.main(ActivityThread.java:5254)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)

这给了我一个结果,但没有给出前500条记录的结果,但只给出了500条记录结果。

4 个答案:

答案 0 :(得分:1)

你必须添加order by子句来制作&#34; desc&#34;工作:

SELECT * FROM UnMappText WHERE updateTime = '0' order by "field_name_to_order" desc LIMIT 0, 500;

答案 1 :(得分:0)

func foo (a: Int, c: Int, b: Int = 0) { //put your parameter with default value at the end print(a + b + c) } //you don't need to specifying a value for parameter b foo(10, 11) //21 保留关键字,不能用作列名。

请使用类似desc的内容。

供参考:https://www.sqlite.org/lang_keywords.html

或者您错过了description属性

之前的ORDER BY子句

DESC

一样

答案 2 :(得分:0)

如果你想检查前500条记录而没有在updateTime上排序,那么试试这个

SELECT * FROM (SELECT * FROM UnMappText LIMIT 0,500) as t  WHERE t.updateTime = '0' ;

如果你想排序然后检查前500条记录,那么试试这个

SELECT * FROM (SELECT * FROM UnMappText order by updateTime LIMIT 0,500) as t  WHERE t.updateTime = '0' ;

答案 3 :(得分:0)

试试这个......

SELECT * FROM (SELECT * FROM UnMappText order by updateTime LIMIT 500) as t  WHERE t.updateTime = '0' ;