如何每周总结sqlite数据

时间:2013-12-04 13:08:09

标签: android database eclipse sqlite cursor

我想每周对变量“schritte”求和并将其保存在额外的数据库中

我创建了我的数据库:

db = openOrCreateDatabase("myDB", MODE_PRIVATE, null);
//      db.execSQL("drop table schritte");
        String create = "create table if not exists schritte(bewegung TEXT, dauer TEXT, sdf DATE Default (datetime('now','localtime')));";
        db.execSQL(create);

并且有我出现数据库的方法

public void btnHandlerAnzeigen_Schritte(View v) {

        textViewSQLSchritt.setText("");
        Cursor cursor = db.rawQuery("select * from schritte", null);

        if (cursor.moveToFirst()) {
            do {

                int schritte = cursor.getInt(0);
                String dauer = cursor.getString(1);
                String date = cursor.getString(2);
                textViewSQLSchritt.append("Schritte:  " + schritte + "  " + dauer + "\n"
                        + date + "\n\n");
            } while (cursor.moveToNext());

        }
        //here i have tried to make a sum but Im unable to finish it
        Cursor cursor2 = db.rawQuery("select strftime('%W',_id) as week, sum(value) as total from schritte  GROUP BY week_of_year order by _id desc", null);

    }

0 个答案:

没有答案