sql正确分组我的表
我使用MS Access是为了通过SQL处理表。我想对我的表进行适当的分组,这是我想做的一个例子。假设我有一张这样的桌子:sql正确分组我的表,sql,ms-access,Sql,Ms Access,我使用MS Access是为了通过SQL处理表。我想对我的表进行适当的分组,这是我想做的一个例子。假设我有一张这样的桌子: Cool? | Age Yes | 15 No | 34 No | 12 Yes | 26 Yes | 10 我想要的是结果表来显示有多少ppl是酷的或者没有按年龄分组。例如,在本例中,它将是: AGE | Count that are cool | Count that is Not cool <25
Cool? | Age
Yes | 15
No | 34
No | 12
Yes | 26
Yes | 10
我想要的是结果表来显示有多少ppl是酷的或者没有按年龄分组。例如,在本例中,它将是:
AGE | Count that are cool | Count that is Not cool
<25 | 2 | 1
>=25 | 1 | 1
年龄|冷静的计数|不冷静的计数
=25 | 1 | 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
age=25时的case,则'>=25'结束为age,计数(age=25时的case,则为1,否则为null结束)为[count that Not cool]
来自表1
年龄=25岁时按情况分组,然后“>=25”结束