gpt4 book ai didi

mysql - 统计 mysql 的分组依据和大小写

转载 作者:行者123 更新时间:2023-11-29 11:08:32 24 4
gpt4 key购买 nike

我试图通过计算每个人的生日来获取他们的年龄。现在我需要将我已经实现的它们分组。现在我想要的是计算第 20 组及以下组中有多少个,依此类推。

这是我的查询

select case when datediff(now(), birthday) / 365.25 > 50 then '51 & over' when datediff(now(), birthday) / 365.25 > 30 then '31 - 50' when datediff(now(), birthday) / 365.25 > 19 then '20 - 30' else 'under 20' end as age_group from members

结果是

enter image description here

我尝试通过下面的查询对其进行分组

select case when datediff(now(), birthday) / 365.25 > 50 then '51 & over' when datediff(now(), birthday) / 365.25 > 30 then '31 - 50' when datediff(now(), birthday) / 365.25 > 19 then '20 - 30' else 'under 20' end as age_group from members group by age_group

结果将是 enter image description here

但是我需要的是这样的 enter image description here

**注意:照片已编辑。

我如何实现需要将计数结果放入图表中。

最佳答案

将查询包装成与此类似:

Select age_group, count(*)
From (
// your original query here
) t
Group by age_group

关于mysql - 统计 mysql 的分组依据和大小写,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40989682/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com