我的数据库中有下表:
database.execSQL("create table " + TABLE_LOGS + " ("
+ COLUMN_ID + " integer primary key autoincrement,"
+ COLUMN_ID_DAY_EXERCISE + " integer not null,"
+ COLUMN_REPS + " integer not null,"
+ COLUMN_WEIGHT + " real not null,"
+ COLUMN_1RM + " real not null,"
+ COLUMN_DATE + " integer not null"
+ ")");
我在 COLUMN_DATE 字段(整数)中存储了一个 unix 时间戳。
现在我有以下函数来获取所有记录:
public Cursor fetchCurrentLogs(long dayExerciseDataID) {
// where day = today
Cursor cursor = database.rawQuery("select " + MySQLiteHelper.COLUMN_ID + "," + MySQLiteHelper.COLUMN_REPS + ", " + MySQLiteHelper.COLUMN_WEIGHT + " " +
"from " + MySQLiteHelper.TABLE_LOGS + " " +
"where " + MySQLiteHelper.COLUMN_ID_DAY_EXERCISE + " = '" + dayExerciseDataID + "'", null);
if (cursor != null) { cursor.moveToFirst(); }
return cursor;
}
现在我想做的是,我想让这个函数只抓取今天的记录。
然后我想让另一个函数完全相同,但是我希望它获取前一天的记录,而不是获取今天的记录。以前,我的意思是最近一天的记录不是今天。所以可能是昨天,或者三天前,或者一个月前。
我知道在 MySQL 中你可以在当天做这样的事情:
where date_format(from_unixtime(COLUMN_DATE), '%Y-%m-%d')= date_format(now(), '%Y-%m-%d')
SQLite 的等价物是什么?
另外,任何人都可以帮我解决上面提到的前一天的 where 子句吗?
非常感谢。