2012-02-05 66 views
0

我有一个浮点数值的游标,用于描述我的人体重,以千克为单位。按范围分组我的SQL浮点值

所以我所有的人在我的数据库有这个样子:

NAME - WEIGHT: 
John: 85.3 
Michael:80.3 
Lisa 58.2 
Christopher: 75.0 

我想要做的就是在重量范围内一个ListView显示它们。

"50-60": 1 people 
"60-70": 1 people 
"70-80": 2 people 
"80-90": 0 people 

我打算使用一个ListView与SimpleCursorAdapter,但我不知道如何将它们分组...

感谢很多的帮助沿线的

回答

1

的东西:

select 
sum(case when weight > 60 and weight <= 70 then 1 else 0 end) as weight1, 
sum(case when weight > 60 and weight <= 80 then 1 else 0 end) as weight2 
from myTable 
+0

很好,但我不能在CursorAdaptor中使用它,因为光标大小== 1,有没有一种方法来改善?为了用结果填充ListView,我需要重新创建一个数组,对吗? – 2012-02-05 20:08:27

+0

不知道答案,我怕,只有最小的Android体验。我猜你或者需要做一个数据透视表(我不认为这是支持的),或者将这些列吐出一个数组/列表/其他数据。 – YXD 2012-02-05 22:29:39