I am trying execute below query but I get misuse of aggregate function sum()
Query
select max(sum(entry.amount)),category.name from entry,category where entry.amount<0 and entry.cid=category.cid group by category.name
LogCat Output
android.database.sqlite.SQLiteException: misuse of aggregate function sum() (code 1): , while compiling: select sum(entry.amount),category.name from entry,category where entry.amount<0 and entry.cid=category.cid group by category.name 09-22 20:20:18.626: E/AndroidRuntime(4093): at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
Any suggestions ? regards, Brother
You cannot aggregate values twice in a single query, but this can be solved with a subquery.
Try:
Notes :
Untested
Not sure about the logic of the query: you are aggregating values so that only one entry remains, so querying category.name does not make sense