I am trying to get the values from database for a bar chart in android.
id amount status month
1 3567 + 4
2 5673 - 3
3 2356 + 2
4 789 - 8
5 1789 + 8
Please consider this table. (I'm sorry I could not add an image). Since, I need to get the values for a bar chart, I am wanting to have month on the x-axis and amount on the y-axis. The bar chart should be income vs expense chart.
I have applied the following query:
Cursor c=db1.rawQuery("select distinct month, (select sum(amount) from expenses where status like '+' group by month) as income, (select sum(amount) from expenses where status like '-' group by month)as expense from expenses", null);
and I am getting the following result:
month income expense
4 2356 5673
3 2356 5673
2 2356 5673
8 2356 5673
instead of
month income expense
4 3567 null
3 null 5673
2 2356 null
8 1789 789
I want that if there are more rows where (let's say, month=4 and status="+", amount=20), then 3587 should be the result instead of 3567.
Thanks for your time and help.
Aucun commentaire:
Enregistrer un commentaire