在Android中使用WHERE子句的日期顺序

时间:2013-01-10 06:27:22

标签: android sqlite

我想用WHERE子句按升序检索所有记录。但是在我的查询中包含WHERE条件的位置?升级顺序正常。

这是我的代码。首先我正在处理这个查询,但在这里我无法实现ORDER BY子句。

Cursor tripdaycursor = sdb.rawQuery(
  "select TripDay_Id, Tripday_Date, Tripday_ParsingDate,
  Trip_Complete, TripDay_Endkm, TripDay_Count, Tripday_EndPlace
  FROM TripDay WHERE Trip_Id="+record, null);

所以我尝试了以下代码升序:

String recordid=Integer.toString(record), Trip_Id="Trip_Id", TripDay_Id="TripDay_Id",
  Tripday_Date="Tripday_Date", Tripday_ParsingDate="Tripday_ParsingDate",
  Trip_Complete="Trip_Complete", TripDay_Endkm="TripDay_Endkm",
  TripDay_Count="TripDay_Count", Tripday_EndPlace="Tripday_EndPlace",
  TripDay = "TripDay";
Cursor tripdaycursor = sdb.query(TripDay, new String[] {
  TripDay_Id, Tripday_Date, Tripday_ParsingDate, Trip_Complete, TripDay_Endkm,
  TripDay_Count, Tripday_EndPlace}, null, null, null, null,
  Tripday_ParsingDate + " ASC");

但我希望在单个查询中使用WHERE子句并按升序排列这两个条件。怎么做?

1 个答案:

答案 0 :(得分:0)

您可以在where子句后面的查询中添加“按Column_Name排序”。像这样的东西,你要按升序排序的列

Cursor tripdaycursor = sdb.rawQuery("select TripDay_Id,Tripday_Date,Tripday_ParsingDate,Trip_Complete,TripDay_Endkm,TripDay_Count,Tripday_EndPlace from TripDay where Trip_Id="+record + " order by " + columnName,null);