标签:年龄段统计
-- 处理名单丢失
SELECT
u.`user_id` u_userid,
o.`user_id` o_userid,
o.*
FROM
`tb_gh_orders` o
LEFT JOIN `tb_gh_user` u
ON o.`user_id` = u.`user_id`
WHERE o.`course_id` = 128
AND o.`order_state` = ‘1‘ ;
-- 年龄段统计
SELECT
T1.*,
CONCAT(LEFT (T1.C1 / T2.C2 * 100, 5), ‘%‘) P
FROM
(SELECT CASE WHEN SUBSTRING(U.ID_NUM, 7, 3)=‘‘ THEN ‘无身份证‘ ELSE
CONCAT(SUBSTRING(U.ID_NUM, 9, 1), ‘0后‘) END AGE,
SUBSTRING(U.ID_NUM, 7, 3) YEAR1,
COUNT(*) C1
FROM
TB_GH_USER U
GROUP BY SUBSTRING(U.ID_NUM, 7, 3)) T1,(SELECT COUNT(*) C2 FROM TB_GH_USER U2) T2
本文出自 “Java乐园” 博客,请务必保留此出处http://hebinteng.blog.51cto.com/7967512/1971348
标签:年龄段统计
原文地址:http://hebinteng.blog.51cto.com/7967512/1971348