使用SQLite Select功能

时间:2011-06-07 09:56:49

标签: android sqlite

我创建了一个数据库,一切正常。但是我怎么能得出最后五行,其中一列的值是例如1。

选择和插入功能具有同步功能,因此读取和插入不会同时发生。有超过300个行,但我只需要获取最后5行的游标对象(所以我得到一行中的所有列),其中一列的值为1。

感谢您的帮助!

3 个答案:

答案 0 :(得分:0)

SELECT *                     -- list of the columns you want
  FROM table
 WHERE column1 = 1           -- rows with column1 = 1
 ORDER BY (ordering columns) -- columns by which you want to order
 LIMIT 5                     -- and get the last 5

答案 1 :(得分:0)

我认为你想要选择前五行都有一个值为1的特定列。如果是这样,使用WHERELIMIT语句应该会有所帮助:

SELECT * FROM tbl WHERE the_column = 1 LIMIT 5

答案 2 :(得分:0)

您可以使用方法database.query(); 如下:

Cursor cursor = database.query(false, TABLE,new String[] {COLUMNS_TO_SELECT},"YOUR_WHERE_CLAUSE", null, null, null, null /*ORDER BY*/, "5"/*YOUR_LIMIT*/);

查看Documentation