如何在Android Sqlite中按月和年对数据进行排序

时间:2013-09-16 11:49:49

标签: android sqlite

cursor = mRecordDB.query(POPDatabase.RECORD_TABLE, new String[] 
             { POPDatabase.RECORD_ID, 
               POPDatabase.RECORD_DATE, 
               POPDatabase.RECORD_DETAILS, 
               POPDatabase.RECORD_DEBIT, 
               POPDatabase.RECORD_CREDIT, 
               POPDatabase.RECORD_COMPANY 
              }, null, null,null, null, POPDatabase.RECORD_DATE + " ASC ");

此查询显示:

01-09-2013
02-09-2013
03-08-2013
04-08-2013
05-09-2013

但我想按月分类:

03-08-2013
04-08-2013
01-09-2013
02-09-2013
05-09-2013

1 个答案:

答案 0 :(得分:-2)

Cursor cursor = sqldb.rawQuery("SELECT EndUsers.Name as EndUserName , DistributorMaster.* FROM DistributorMaster,EndUsers where EndUsers.SAPCode=DistributorMaster.CreatedBy order by ID DESC",null);

或 Query有两种语法,你使用的语法,最后一列代表order by,你只需要指定你要做什么列orderby +“ASC”(或)orderby +“DESC”

Cursor c = scoreDb.query(DATABASE_TABLE, rank, null, null, null, null, yourColumn+" DESC"); 

请参阅this 文档以了解有关查询方法的更多信息。

我希望它对你有用。