奇怪的sql

 

 

身份证按年龄段分组统计

SELECT
    CASE
WHEN (age >= 10 AND age <= 28) THEN
    '10-28'
WHEN (age >= 29 AND age <= 38) THEN
    '29-38'
ELSE
    '38-'
END 'eag_layer',
 count(*) emps
 
from
(SELECT F_IDCard,FLOOR(DATEDIFF(DY, substring(F_IDCard,7,4), GETDATE()) / 365.25) as age FROM [WisdomPoliceStation].[dbo].[T_InternetBarRecord])as b

GROUP BY
    CASE
WHEN (age >= 10 AND age <= 28) THEN
    '10-28'
WHEN (age >= 29 AND age <= 38) THEN
    '29-38'
ELSE
    '38-'
END
ORDER BY
    1;

 

posted @ 2021-08-11 16:54  陨落&新生  阅读(40)  评论(0编辑  收藏  举报