美好的一天!我需要一种方法来查询每个特定年龄范围的成员(member)数量 我的 table 看起来像这样
member | Age
1 | 15
2 | 15
3 | 17
4 | 18
5 | 18
6 | 18
7 | 20
我需要确定每个特定年龄的成员数量,但问题是,过滤器附带的范围格式为 15-20、21-25、30-35 等。 例如,如果我选择的范围是 15-20,我需要计算每个特定年龄 15、16、17、18、19、20 的成员数量。 感谢您的帮助
最佳答案
这应该有效,
select
tb.Age `Age`,
count(tb.member) `count`
from
(select
member,
case when Age >=15 & Age<20 then '15-20'
when Age >=20 & Age<25 then '20-25'
when Age >=25 & Age<30 then '25-30'
else '30+' end `Age`
from tablename ) as tb
group by `Age`
关于mysql - 带范围的计数查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49000558/