统计年龄(10分)

  • 主题发起人 主题发起人 anthonytang
  • 开始时间 开始时间
A

anthonytang

Unregistered / Unconfirmed
GUEST, unregistred user!
我用sql server7统计16-25,26-35,36-45各段的人数,表rsdagl中有一个chusheng字段(出生日期)
。请求各位大侠指导!
 
select count(cushen) from rsdagl
where cushenf >16 and cusheng<25
union all
select count(cushen) from rsdagl
where cushenf >26 and cusheng<35
union all
select count(cushen) from rsdagl
where cushenf >36 and cusheng<45


这样统计出来应该有三条纪录,分别是三个你需要的数字,ok???
给分,呵呵

 
cusheng存的是日期,不是年龄吧。呵呵
 
where year(now)-year(chusheng)
 
to xelloss
好像是哦,呵呵(傻笑ing~~~~~~~~~)
 
不行吗,统计出来都是0!chusheng字段是datetime型。请回复!!
 
select
sum(case when datediff(year,chusheng,getdate())>16 and
when datediff(year,chusheng,getdate())<25 then 1 else 0 end) as '16-25',
sum(case when datediff(year,chusheng,getdate())>25 and
when datediff(year,chusheng,getdate())<36 then 1 else 0 end) as '26-35',
.........

 
变能一下用分类汇总group by 如何? 或许也可以解决你的问题
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
D
回复
0
查看
2K
DelphiTeacher的专栏
D
D
回复
0
查看
2K
DelphiTeacher的专栏
D
后退
顶部