In my application I have to retrieve data from a database. My requirement is I have to retrieve data by satisfying the condition that I have to sum the total column where group column should be household.
I have written this query:
public String addhousehold()
{
long sum = 0;
Cursor cursor1 = db.rawQuery("SELECT SUM("+(KEY_TOTAL)+") FROM incomexpense WHERE groups=Income", null);
if(cursor1.moveToFirst())
{
sum = cursor1.getLong(0);
}
cursor1.close();
String housetotal=String.valueOf((long)sum);
System.out.println("house="+housetotal);
return housetotal;
}
But I get an error:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.budget1/com.budget1.Report}:
android.database.sqlite.SQLiteException: no such column: Income: , while compiling: SELECT SUM(total) FROM incomexpense WHERE groups=Income.
As I am new to this please help me. Thanks in advance
The query should be:
if (Income) is a string.. and if not, then you should make sure the column exists..