我如何分裂男性和女性並計算21歲以下的人?MySQL選擇男性和女性21以下
到目前爲止,我有這個(但值不正確):
SELECT
COUNT(if(gender='M', 1, 0)) AS males,
COUNT(if(gender='F', 1, 0)) AS females
FROM
dependent
WHERE
YEAR(CURRENT_TIMESTAMP) - YEAR(dob) - (RIGHT(CURRENT_TIMESTAMP, 5) < RIGHT(dob, 5)) < 21
輸出應該是這樣的:
男性|女性
1 | 2