ä¾ï¼è¡¨ tab1 ,åºçæ¥æå段为 rqï¼sqlè¯å¥å¦ä¸
select a.age,count(*) fromå
³é®è¯å¥ï¼select year(getdate()) - year(rq) as "age" from tab1
yearå½æ°è·åç³»ç»æ¥æä¸åºçæ¥æç年份ï¼å°å¹´ä»½ç¸åå³å¹´é¾ï¼å½ç¶ä¹å¯ä»¥æ ¹æ®éæ±ï¼ååºæ份ï¼è¿è¡è¿ç®ï¼è·å¾æ´ç²¾ç¡®çå¨å²ã
给的是具体的年月日,我只要年龄啊,怎么排除啊
追答那就加 where 子句了 计算年龄那就年份相减了
追问不好意思给个完整的吧,我们这是选修课,才上六周,实在白痴
追答select datepart(YYYY,getdate())-datepart(YYYY,birthday) as age, count(*)
from table
where birthday >='1992-08-27 00:00:00.000'
group by datepart(YYYY,getdate())-datepart(YYYY,birthday)