奇怪的sql

2021/8/11 19:06:29

本文主要是介绍奇怪的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;

 



这篇关于奇怪的sql的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程