Oracle 根据出生日期计算年龄
select(c.name)姓名,(select(to_char(sysdate,'YYYY')-to_char(c.birthdate,'YYYY'))agefromC...
select
(c.name)姓名,
(select (to_char(sysdate,'YYYY')-to_char(c.birthdate, 'YYYY')) age from C c)年龄,
(b.P_NAME)项目名称,
(a.NUMBER)流水号
from
A a,
B b,
C c
where
a.id=b.id
and
a.id=c.id
说明: c.birthdate是date类型,‘YYYY-MM-DD 00:00:00'
以上提示单行查询语句返回多行 展开
(c.name)姓名,
(select (to_char(sysdate,'YYYY')-to_char(c.birthdate, 'YYYY')) age from C c)年龄,
(b.P_NAME)项目名称,
(a.NUMBER)流水号
from
A a,
B b,
C c
where
a.id=b.id
and
a.id=c.id
说明: c.birthdate是date类型,‘YYYY-MM-DD 00:00:00'
以上提示单行查询语句返回多行 展开
5个回答
展开全部
肯定的,你的子查询写,要么是写多了,要么是写少了。
写多了,可以不用写子查询的
(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)年龄,
写多了,可以不用写子查询的
(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)年龄,
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
试试看子查询加上rownum=1
select
(c.name)姓名,
(select (to_char(sysdate,'YYYY')-to_char(c.birthdate, 'YYYY')) age from C c where rownum=1)年龄,
(b.P_NAME)项目名称,
(a.NUMBER)流水号
from
A a,
B b,
C c
where
a.id=b.id
and
a.id=c.id
select
(c.name)姓名,
(select (to_char(sysdate,'YYYY')-to_char(c.birthdate, 'YYYY')) age from C c where rownum=1)年龄,
(b.P_NAME)项目名称,
(a.NUMBER)流水号
from
A a,
B b,
C c
where
a.id=b.id
and
a.id=c.id
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
把select换成ceil( months_between(sysdate,c.birthdate)/12)
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
months_between(trunc(sysdate,'yyyy'),trunc(c.birthdate,'yyyy'))/12
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询