0

我想从 pro_price 查询今年的总金额.. sqlite 查询语句 getDate().endWith(getThisYear()) 有什么问题吗?

 public double SumPriceYear(){

Cursor sum = ourDatabase.rawQuery("SELECT SUM( " + Pro_Price + " ) FROM "+ TABLE_NAME + " Where " + Pro_Date + " = '" + getDate().endsWith(getThisYear()) + "' ", null);
if(sum.moveToFirst())
{
    return sum.getDouble(0);
}

return sum.getDouble(0);

}

4

1 回答 1

0

您的选择总和应该有一个列名,而不是一个值。此外,您不应将日期与一年进行比较。它不会匹配。您需要逐年比较。

尝试这个:

public double SumPriceYear(){

Cursor sum = ourDatabase.rawQuery("SELECT SUM(COLUMN_NAME) FROM "+ TABLE_NAME + " WHERE date(" + Pro_Date + ",'%Y') = '" + getDate().endsWith(getThisYear()) + "' ", null);
if(sum.moveToFirst())
{
    return sum.getDouble(0);
}

    return sum.getDouble(0);
}

我对以下内容进行了更改:

  • 总和(COLUMN_NAME)
  • WHERE date(" + Pro_Date + ",'%Y')
于 2013-07-10T16:47:22.697 回答