我想重写这个 sql 查询,以便他在没有匹配项的情况下显示相应年龄范围的 0 记录,并且我希望他此时计算 Member 的每个值的百分比而不是“0”,任何人都可以帮助我如何实现这一目标?
SELECT COUNT(Name) * 100 /
(select COUNT(*) from 'cities'
WHERE city= 'Hoeselt' AND Member = '0' ) AS 'perc',
CASE
WHEN age <= 30 THEN '18-30'
WHEN age <= 50 THEN '31-50'
ELSE '50+'
END AS age, COUNT(*) AS n
FROM 'cities'
WHERE city= 'Hoeselt' AND elected='yes' AND Member= '0'
GROUP BY CASE
WHEN age <= 30 THEN '18-30'
WHEN age <= 50 THEN '31-50'
ELSE '50+'
END