关于出身日期的分析

yczhengyong 2003-10-21 11:20:09
表中有一字段为出生日期,客户要求能根据当前年份(如2003)得出各个年龄段(如18-25,26-35,36-45,46-55)的人数。奉上小弟最后三十分!!
1980-03-07
1969-11-29
1964-02-11
1979-10-24
1970-01-12
1974-04-08
1983-03-11
1975-02-23
1977-06-26
1981-07-24
1977-06-05
1980-07-14
1982-10-29
1975-01-27
1975-03-18
1966-01-01
1983-03-01
1964-01-15
1979-10-05
1968-03-28
1982-01-20
1977-04-05
1976-08-25
1980-12-01
1983-06-20
1973-05-21
1979-08-07
1978-12-15
1976-12-23
1975-02-08
1963-10-09
...全文
50 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
SwordsmanF 2003-10-21
  • 打赏
  • 举报
回复
select
count(*)
from
table
where
datediff(year,birthday,getDate())>18 and datediff(year,birthday,getDate())<25

其它类同
pengdali 2003-10-21
  • 打赏
  • 举报
回复
select
case
when datediff(year,a,getdate()) between 18 and 25 then '18-25'
when datediff(year,a,getdate()) between 26 and 35 then '26-35'
when datediff(year,a,getdate()) between 36 and 45 then '36-45'
when datediff(year,a,getdate()) between 46 and 55 then '46-55'
end 年龄段,
count(*) 人数
from @a group by
case
when datediff(year,a,getdate()) between 18 and 25 then '18-25'
when datediff(year,a,getdate()) between 26 and 35 then '26-35'
when datediff(year,a,getdate()) between 36 and 45 then '36-45'
when datediff(year,a,getdate()) between 46 and 55 then '46-55'
end

34,875

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧