快上网专注成都网站设计 成都网站制作 成都网站建设
成都网站建设公司服务热线:028-86922220

网站建设知识

十年网站开发经验 + 多家企业客户 + 靠谱的建站团队

量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决

oracle怎么计算年龄,oracle周岁计算

Oracle中如何计算年龄

SQL语句如下:

创新新互联,凭借10余年的成都做网站、网站制作经验,本着真心·诚心服务的企业理念服务于成都中小企业设计网站有上1000+案例。做网站建设,选创新互联。

select floor(MONTHS_BETWEEN(sysdate,date'2016-1-1')/12) as age from dual;

结果:

oracle根据出生日期算年龄

select floor(months_between(to_date(concat(extract(year from sysdate),'-10-31'),'YYYY-MM-DD'),to_date(生日的日期,'yyyy-mm-dd'))/12) from table_name

floor 向下取整

months_between 日期相差的月份数

concat字字符串连接

extract(year from sysdate) 返回当前日期的年份

Oracle 根据出生日期计算年龄

肯定的,你的子查询写,要么是写多了,要么是写少了。

写多了,可以不用写子查询的

(select

(to_char(sysdate,'YYYY')-to_char(c.birthdate,

'YYYY'))

age

from

C

c)年龄,

改为

to_char(sysdate,'YYYY')-to_char(c.birthdate,

'YYYY')

年龄即可

写少了.(先确定id在c表中没有重复啊。)

from中去掉c

,然后在

(select

(to_char(sysdate,'YYYY')-to_char(c.birthdate,

'YYYY'))

age

from

C

c)年龄,

改为

(select

(to_char(sysdate,'YYYY')-to_char(c.birthdate,

'YYYY'))

age

from

C

c

where

c.id=a.id)年龄,

oracle 年龄段统计

年龄段统计可用case when 语句。

如test表中有以下数据:

其中18-29岁为青年,30-49岁为中年,50岁以上为老年,先统计各个年龄段人数,可用如下语句:

select case when age between 18 and 29 then '青年' when age between 30 and 59 then '中年' when age=60 then '老年' end as 年龄段,

count(*) as 人数 

from test

group by case when age between 18 and 29 then '青年' when age between 30 and 59 then '中年' when age=60 then '老年' end;

统计结果:


文章标题:oracle怎么计算年龄,oracle周岁计算
URL地址:http://6mz.cn/article/dssdjop.html

其他资讯