我有一张桌子,里面有生日和性别
SELECT `tblresultdatetime`, `tblresultbirthdate`, `tblgendertexten`
FROM `ci_wizard_results`
INNER JOIN ci_wizard_genders ON ci_wizard_results.tblresultgender = ci_wizard_genders.tblgenderid
所以我想创建一个表格,指出年龄组等。
我相信我首先必须将日期转换为年龄:
select *,year(`tblresultdatetime`)-year(`tblresultbirthdate`) - (right(`tblresultdatetime`,5) < right(`tblresultbirthdate`,5)) as age from `ci_wizard_results`
但在那之后,我不知道如何继续。我相信我应该使用案例:
select *,year(`tblresultdatetime`)-year(`tblresultbirthdate`) - (right(`tblresultdatetime`,5) < right(`tblresultbirthdate`,5)) as age,
count(case when age <= 30 and age> 39 then 1 end) as agegroup3039
from `ci_wizard_results`
但是你不能使用别名以防万一,所以我有点卡住了。有什么建议我可以继续吗?
(我的最终目标是通过 reportico 在报告中显示数据)
谢谢!