在所有 android 版本中不存在相同的 SQLite 查询 运行

Same SQLite Query doesnot run in all the android version

我正在 SQLite 中执行以下查询:

SELECT * from ValueTable where SrNo = (with t as(SELECT SrNo,Value2 from ValueTable where Value2<'600' ) SELECT SrNo from t order by Value2 DESC limit 1)

table 架构是

SrNo   Value1   Value2

 1       200     450

 2       500     350

 3       100     500

所以每当我在我的代码中 运行 上面的查询时,它在棒棒糖版本上运行良好。但是在较低版本上 运行 时会出错。我不知道为什么。它在上面的查询中给出了 't' 附近的错误。我到底错过了什么?提前致谢。

编辑: 这是错误日志:

     Caused by: android.database.sqlite.SQLiteException: near "t": syntax error (code 1): , while compiling: SELECT * from ValueTable where SrNo = (with t as(SELECT SrNo,Value2 from ValueTable where Value2<'600' ) SELECT SrNo from t order by Value2 DESC limit 1)
            at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
            at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:893)
            at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:504)
            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:1339)
            at android.database.sqlite.SQLiteDatabase.rawQuery(SQLiteDatabase.java:1278)
            at kunal.trial.trialsqliteinallversions.TestAdapter.getTestData(TestAdapter.java:56)
            at kunal.trial.trialsqliteinallversions.MainActivity.LoadEmployee(MainActivity.java:54)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at android.view.View.onClick(View.java:3843)
            at android.view.View.performClick(View.java:4463)
            at android.view.View$PerformClick.run(View.java:18789)
            at android.os.Handler.handleCallback(Handler.java:808)
            at android.os.Handler.dispatchMessage(Handler.java:103)
            at android.os.Looper.loop(Looper.java:193)
            at android.app.ActivityThread.main(ActivityThread.java:5299)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:825)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:641)
            at dalvik.system.NativeStart.main(Native Method)

WITH 子句支持已添加到 SQLite 3.8.3

API 20 级以下使用 older version of SQLite

重构您的查询,以在所有目标 API 级别上支持 SQL 获得您想要的结果。