第1问第2种情形精确计算年龄段,
第1问第1种情形见18楼Sql语句!- SELECT nld AS 精确计算年龄段,count(*) as 人数 from
- (
- SELECT 姓名,datediff(dd,出生年月,getdate())/365 as 精确年龄,
- case
- when datediff(dd,出生年月,getdate())/365>=36 and datediff(dd,出生年月,getdate())/365 <=40 THEN '36-40'
- when datediff(dd,出生年月,getdate())/365>=41 and datediff(dd,出生年月,getdate())/365 <=45 THEN '41-45'
- when datediff(dd,出生年月,getdate())/365>=46 and datediff(dd,出生年月,getdate())/365 <=50 THEN '46-50'
- when datediff(dd,出生年月,getdate())/365>=51 and datediff(dd,出生年月,getdate())/365 <=55 THEN '51-55'
- when datediff(dd,出生年月,getdate())/365>=56 and datediff(dd,出生年月,getdate())/365 <=60 THEN '56-60'
- when datediff(dd,出生年月,getdate())/365>=61 and datediff(dd,出生年月,getdate())/365 <=65 THEN '61-65'
- when datediff(dd,出生年月,getdate())/365>=66 and datediff(dd,出生年月,getdate())/365 <=70 THEN '66-70'
- when datediff(dd,出生年月,getdate())/365>=71 and datediff(dd,出生年月,getdate())/365 <=75 THEN '71-75'
- when datediff(dd,出生年月,getdate())/365>=76 and datediff(dd,出生年月,getdate())/365<=80 THEN '76-80'
- when datediff(dd,出生年月,getdate())/365>=81 and datediff(dd,出生年月,getdate())/365 <=85 THEN '81-85'
- when datediff(dd,出生年月,getdate())/365>=86 and datediff(dd,出生年月,getdate())/365 <=90 THEN '86-90'
- END AS nld
- from dbo.Sheet1$
- ) a
- GROUP BY nld
复制代码 |