说明:
用于分组统计数据
语句:
SELECT
a.nld AS '年龄段',
count( * ) AS '人数'
FROM
(
SELECT
CASE
WHEN
s.age < 20 THEN '小于20' WHEN s.age >= 21
AND s.age <= 30 THEN '21-30' WHEN s.age >= 31
AND s.age <= 40 THEN '31-40' WHEN s.age >= 41
AND s.age <= 50 THEN '41-50' WHEN s.age >= 51
AND s.age <= 60 THEN '51-60' WHEN s.age >= 61
AND s.age <= 70 THEN '61-70' WHEN s.age > 70 THEN
'大于70'
END AS nld
FROM
(
SELECT
y.zjy_user_age AS age
FROM
zjy_volunteer_troops_relation t
INNER JOIN ( SELECT * FROM zjy_volunteer_troops WHERE zjy_tenant_id IN ( @tendant_ID ) AND zjy_deleted = 0 ) f ON t.zjy_troops_id = f.id
INNER JOIN zjy_applet_user y ON y.id = t.zjy_applet_user_id
WHERE
t.zjy_deleted = 0
AND y.zjy_deleted = 0
) s
) a
GROUP BY
a.nld