按多列请求分组,结果在一行上-Android SQLite

按多列请求分组,结果在一行上-Android SQLite,android,sql,sqlite,Android,Sql,Sqlite,我需要做一些选择计数()分组依据2列(月份和类型)请求。我可以提出以下要求: select Month, Type, Count() from MyTable group by Month, Type 我的问题是,我想使用光标在Android Listview中显示结果: 每月一行 类型的计数(固定数和已知数) 可能是这样的: select Month, Count(Type = A), Count(Type = B), Count(Type = C) from MyTable group

我需要做一些
选择
<代码>计数()
分组依据
2列(月份和类型)请求。我可以提出以下要求:

select Month, Type, Count()
from MyTable
group by Month, Type
我的问题是,我想使用光标在Android Listview中显示结果:

  • 每月一行
  • 类型的计数(固定数和已知数)
可能是这样的:

select Month, Count(Type = A), Count(Type = B), Count(Type = C)
from MyTable
group by Month
数据库

Month   |   Type
-------- ---------
Feb 15  |   A
Feb 15  |   B
Dec 15  |   A
Dec 15  |   A
Dec 15  |   B
Dec 15  |   C
预期结果

Month   |  'COUNT(A)'  |   'COUNT(B)'  |   'COUNT(C)'
-------- -------------- --------------- -------------
Feb 15  |   1          |   1          |   0
Dec 15  |   2          |   1          |   1
可能吗

select 
 month, 
 sum(case when "Type" = 'A' then 1 else 0 end) as "count(a)",
 sum(case when "Type" = 'B' then 1 else 0 end) as "count(b)",
 sum(case when "Type" = 'C' then 1 else 0 end) as "count(c)"
from 
 mytable 
group by 
 month