如何从android中的sqlite数据库中获取本周的结果。 我以2016-12-04的形式存储了日期。现在,当用户点击一个按钮时,我想在android中显示过去七天的结果(总和)。
if(all=="This Week")
{
query=("Select SUM("+ DataConstants.amount_name+") FROM " + DataConstants.table_name + "WHERE "+ DataConstants.date_name+ "="+ "(WHAT SHOULD I KEEP HERE?)");
cursor= dba.rawQuery(query,null);}
答案 0 :(得分:0)
在SQLite中,您可以获取当前日期并从中减去7天:
query = String.format(
"SELECT SUM(%s) FROM %s WHERE %s >= DATETIME('now', '-7 day');",
DataConstants.amount_name,
DataConstants.table_name,
DataConstants.date_name);
cursor = dba.rawQuery(query, null);
Also, you should change if (all == "This Week")
to if (all.equals("This Week"))