如何使用限制参数在SQLite的查询与Android [英] How to use the LIMIT argument in an SQLite Query with Android

查看:211
本文介绍了如何使用限制参数在SQLite的查询与Android的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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");

这篇关于如何使用限制参数在SQLite的查询与Android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆