获取分类和累积的表数组

时间:2019-04-16 13:37:40

标签: android arrays sqlite

我有一个表,用于存储有关部门和账单的最新信息。我的目标是找到从今天起的过去7天的活动,按部门分类,并加价并将其作为数组返回。

mysql> select * from Item;
+----+------------+--------------+
| ID | Department | Price | Date
+----+------------+--------------+
|  1 | DELL       | 20    | 04/01/2019
|  2 | HP         | 15    | 04/16/2019
|  3 | DELL       | 30    | 03/15/2019
|  4 | ACER       | 15    | 04/16/2019
|  5 | ASUS       | 60    | 04/15/2019
|  6 | HP         | 15    | 04/14/2019
|  7 | DELL       | 30    | 03/30/2019
|  8 | ACER       | 15    | 01/16/2019
|  9 | ASUS       | 60    | 02/15/2019
+----+------------+----------+

到目前为止,我已按日期对表进行了排序:

Cursor cursor = db.rawQuery("SELECT * FROM " + Projects_TABLE + " ORDER BY " + PRO_DATE + " DES", null);

并比较了存储在表中的今天日期减去7天,但我不知道如何以增加的价格退还7天中的每个部门协议 例如,数组的所需结果:

Today Date is 04/16/2019
+----+------------+----------+
| ID | Department | Price 
+----+------------+----------+
|  1 | HP         | 30 
|  2 | ACER       | 15
+----+------------+----------+

这是我的代码

 public  ArrayList<DetailedProject_GS> DB_Display_The_Progress_Weakly() {
        SQLiteDatabase sqLiteDatabase = this.getWritableDatabase ();
        Cursor cursor = db.rawQuery("SELECT * FROM " + Projects_TABLE + " ORDER BY " + PRO_DATE + " DES", null);
        ArrayList<DetailedProject_GS> ProjectsArchive = new ArrayList<>();
        Calendar EndTime = Calendar.getInstance();
        cursor.moveToFirst ();
        while (cursor != null && cursor.getCount () > 0 && !cursor.isAfterLast ()) {
            try {
                SimpleDateFormat simpleDateFormat = new 
 SimpleDateFormat("EEEE dd/MM/yyyy" , Locale.ENGLISH);

                String currentDateandTime = simpleDateFormat.format(new Date());
                Calendar c = Calendar.getInstance();
                c.setTime(simpleDateFormat.parse(currentDateandTime));
                c.add(Calendar.DATE, -7);

                EndTime.setTime(sdf.parse(cursor.getString (cursor.getColumnIndex (PROJECT_H_ENDTIME)) ));// all done
                if (EndTime.after(c)){

                    //Adding CODE HERE
                    ProjectsArchive.add(data);
                }else{

                }
            } catch (ParseException e) {
                e.printStackTrace();
            }
            cursor.moveToNext ();
        }
        cursor.close();
        sqLiteDatabase.close ();
        return ProjectsArchive;
    }

1 个答案:

答案 0 :(得分:0)

如果将日期格式更改为/*0< index < head.rows you get first Column expanded by repeater3*/ repeater3.itemAt(index).children[0] /*0< index < head.columns you get first Row of first Column expanded by repeater3 and repeater2*/ repeater3.itemAt(index).children[0].children[0] /*0< index < 2 you get first Rectangle of first Row of first Column expanded by repeater3 and repeater2 and repeater1*/ repeater3.itemAt(index).children[0].children[0].children[0] ,则只需YYYY-MM-DD

group by department

使用当前日期格式,首先必须将其转换为select department, sum(price) price from item where date >= datetime('now', '-7 day') group by department

YYYY-MM-DD