表内有学生生日字段(1997-5),查找年龄小于20岁的学生的所有信息。

oracle 查询年龄超过20岁的学生? 出生日期给的是年 月 日。要用函数sysdate??

这是表
CREATE table xuesheng(
t_ID varchar(20) primary key,
t_Name varchar(20) not null,
t_address varchar(20) not null,
t_phone char(20) not null,
t_birthday date
);

INSERT INTO xuesheng(t_ID,t_Name,t_address,t_phone,t_birthday) VALUES (1,'李三','成都',1234567,date'2010-2-12');
INSERT INTO xuesheng(t_ID,t_Name,t_address,t_phone,t_birthday) VALUES (2,'王三','江安',123456,date'1991-10-10');
INSERT INTO xuesheng(t_ID,t_Name,t_address,t_phone,t_birthday) VALUES (3,'king','终极',12349,date'1990-11-10');
INSERT INTO xuesheng(t_ID,t_Name,t_address,t_phone,t_birthday) VALUES (4,'梨花','东北',1234,date'1992-10-10');
INSERT INTO xuesheng(t_ID,t_Name,t_address,t_phone,t_birthday) VALUES (5,'李四','成都',13384567,date'1994-10-10');
INSERT INTO xuesheng(t_ID,t_Name,t_address,t_phone,t_birthday) VALUES (6,'李思','成都',12349567,date'1988-10-10');
INSERT INTO xuesheng(t_ID,t_Name,t_address,t_phone,t_birthday) VALUES (7,'王大','成都',12348567,date'1976-10-10');
INSERT INTO xuesheng(t_ID,t_Name,t_address,t_phone,t_birthday) VALUES (8,'Ki','成都',123483567,date'1986-10-10');

 

Oracle数据库;

select * from xuesheng where months_between(sysdate,t_birthday)/12>20;

select * from xuesheng where add_months(t_birthday,20*12) < sysdate;

sqlserver:
select * from xuesheng where datediff(day,t_birthday,getDate())/365>=20

mySQL数据库:

select * from xuesheng where datediff(CURDATE(),t_birthday)/365>=20

 

 

来自:https://zhidao.baidu.com/question/528387517.html

 

posted @ 2019-01-23 09:42  江湖萤火虫  阅读(747)  评论(0编辑  收藏  举报