2016-07-11 15 views
3

に動作していないと私は(3別々のcolumns)に変換しています。それはうまくいきますが、私は結果を月と年で降順で並べ替える必要があります。ここでORDERは、年DESCは私が日付フィールドで<code>table</code>を持っているSQLiteの

は私のクエリです: -

Cursor c = database.rawQuery(
    "select count(*) as TotalCount, tDate, " + 
     "sum(case when type = '1' then Amount else 0 end) \"Income\", " + 
     "sum(case when type = '2' then Amount else 0 end) \"Expenses\", " + 
     "(sum(case when type = '1' then Amount else 0 end) - sum(case when type = '2' then Amount else 0 end)) \"Profit\", " + 
     "strftime('%d', tDate) as DayPart, " + 
     "strftime('%m', tDate) as MonthPart, " + 
     "strftime('%Y', tDate) as YearPart " + 
     "from library " + 
     "group by MonthPart, YearPart Order by YearPart,MonthPart DESC", 
    null 
); 

それはだけMonthPartでないYearPartとMonthPartの両方で降順で表示されます。助けてください。

+1

日付の部分を保管しないでくださいを。 1列として保存する – Jens

答えて

2

私は答えました: -

Cursor c = database.rawQuery(
    "select count(*) as TotalCount, tDate, " + 
      "sum(case when type = '1' then Amount else 0 end) \"Income\", " + 
      "sum(case when type = '2' then Amount else 0 end) \"Expenses\", " + 
      "(sum(case when type = '1' then Amount else 0 end) - sum(case when type = '2' then Amount else 0 end)) \"Profit\", " + 
      "strftime('%d', tDate) as DayPart, " + 
      "strftime('%m', tDate) as MonthPart, " + 
      "strftime('%Y', tDate) as YearPart " + 
      "from library " + 
      "group by MonthPart, YearPart ORDER BY date(tDate) DESC", 
    null 
); 
関連する問題