我正在使用MS Access来通过SQL来使用表格。我想正确地分组我的表,这是我想要做的一个例子。说我有这样一张桌子:
Cool? | Age
Yes | 15
No | 34
No | 12
Yes | 26
Yes | 10
我想要的是生成的表格,以显示有多少人很酷或没有按年龄分组。例如,在这个例子中它将是:
AGE | Count that are cool | Count that is Not cool
<25 | 2 | 1
>=25 | 1 | 1
提前致谢!
答案 0 :(得分:1)
试试这个:
case when age<25 then '<25' when age>=25 then '>=25' end as age, count(case when age<25 then 1 else null end) as [Count that are cool], count(case when age>=25 then 1 else null end) as [Count that is Not cool]
from Table1
group by case when age<25 then '<25' when age>=25 then '>=25' end