如何使用限制参数在SQLite的查询与Android如何使用、参数、Android、SQLite

2023-09-12 09:14:30 作者:吃到苦就是得到了甜

我尝试使用下面的查询,以获得最新的结果,按日期。

I am trying to use the following query to get the most recent result by date.

Cursor cursor = mDb.query(DATABASE_TABLE, new String[] {KEY_DATE, KEY_REPS, 
KEY_WEIGHT}, null, null, null, null, KEY_DATE + "DESC", ???);

我需要使用极限参数(我认为),但它需要一个字符串。我试图创建一个字符串1的值,但没有奏效。我尝试过其他的东西 1的 LIMIT 1 限制1 限制1 限制1

I need to use the limit argument (I believe) but it takes a string. I tried creating a string with a value of "1" but that didn't work. Other things I tried "1" LIMIT 1 "LIMIT 1" Limit 1 "Limit 1"

此外,如果任何人都知道有很大的参考点(比这个除外),实际上显示你各种SQL查询(机器人),这将是非常有益的...

Also, if anyone knows of a great reference site (other than this one) that actually shows you various SQL queries (for ANDROID) that would be very helpful...

编辑 我使用1...得到了错误也许是限制是不是我的问题? 以下是错误:android.database.sqlite.SQLiteException:没有这样的列:dateDESC:在编制:选择日期,重复,质量,测试从ORDER BY dateDESC LIMIT 1

EDIT The error I got from using "1"...perhaps the limit isn't my problem? Here is the error: android.database.sqlite.SQLiteException: no such column: dateDESC: , while compiling: SELECT date, repetitions, weight, FROM TEST ORDER BY dateDESC LIMIT 1

推荐答案

排序编号降序极限1

db.query("table", null, "column=?", new String[]{"value"}, null, null, "id DESC", "1");
 
精彩推荐
图片推荐