【发布时间】:2015-04-10 13:03:37
【问题描述】:
我正在尝试从数据库中获取 android 条形图的值。
id amount status month
1 3567 + 4
2 5673 - 3
3 2356 + 2
4 789 - 8
5 1789 + 8
请考虑这张表。 (很抱歉我无法添加图片)。因为,我需要获取条形图的值,所以我想在 x 轴上有月份,在 y 轴上有金额。条形图应该是收入与支出图表。
我已应用以下查询:
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);
我得到以下结果:
month income expense
4 2356 5673
3 2356 5673
2 2356 5673
8 2356 5673
而不是
month income expense
4 3567 null
3 null 5673
2 2356 null
8 1789 789
我希望如果有更多行(例如,month=4 和 status="+",amount=20),那么结果应该是 3587 而不是 3567。
感谢您的时间和帮助。
【问题讨论】:
标签: android database sqlite union bar-chart