我想创建一个查询,返回本周特定日期的行数。例如,如果dayNumber = 1
,它应该返回 BookSaveTime 是星期一的书籍数量。如果 等,它应该返回星期二的计数dayNumber = 2
。
var week = DateTime.Today.AddDays(-(((int)DateTime.Today.DayOfWeek+6)%7));
return database.ExecuteScalar<int>("SELECT count(*) FROM Book WHERE BookSaveTime > ?;", week);
目前,此查询返回自一周开始以来的书籍数量 - 但我对如何修改它以使其返回给定指定日期的计数感到困惑 - 例如,星期一或星期二。
public MyAppSQLiteDatabase()
{
try
{
database = DependencyService.Get<ISQLiteService>().GetConnection(DbFileName);
database.CreateTable<Book>();
CurrentState = "Database created";
}
catch (SQLiteException ex)
{
CurrentState = ex.Message;
}
}
public int GetDailyCount(int dayNumber){
var day = DateTime.Today.AddDays(-(((int)DateTime.Today.DayOfWeek+6)%dayNumber));
return database.ExecuteScalar<int>("SELECT count(*) FROM Book WHERE BookSaveTime = ?;", day );
}
书类:
public class Book: INotifyPropertyChanged
{
[PrimaryKey, AutoIncrement]
public int ID { get; set; }
private DateTime bookSaveTime;
public DateTime BookSaveTime
{
get
{
return bookSaveTime;
}
set
{
if (bookSaveTime != value)
{
bookSaveTime= value;
OnPropertyChanged("BookSaveTime");
}
}
}
}