按3列排序光标

时间:2014-01-03 17:59:23

标签: android cursor

如何使用nBD.queryORDER BY column1 ASC, then column2 ASC的光标,最后用column3 in order ASC

Cursor D = nBD.query(NOMBRE_TB, columnas, null, null, null, null, column1, null);

在SQL中是:

Cursor c = nBD.rawQuery("SELECT * FROM " + NOMBRE_TB + " ORDER BY " + COLUMN1 + " ASC, " + COLUMN2 + " ASC, " + COLUMN3 + " ASC", null); 

但我想使用cursor D

2 个答案:

答案 0 :(得分:2)

String orderBy = COLUMN1 + " ASC, " + COLUMN2 + " ASC, " + COLUMN3 + " ASC";
Cursor D = nBD.query(NOMBRE_TB, columnas, null, null, null, null, orderBy, null);

答案 1 :(得分:0)

您需要在单个字符串中添加多个Order By子句

String order = "column1 ASC, column2 ASC, column3 ASC";
Cursor D = nBD.query(NOMBRE_TB, columnas, null, null, null, null, order, null);

用真实的列名替换column。这将使您的查询按您希望的方式排序。