当前位置:Gxlcms > 数据库问题 > sql练习题

sql练习题

时间:2021-07-01 10:21:17 帮助过:6人阅读

11) NOT NULL, `birth_date` date NOT NULL, `first_name` varchar(14) NOT NULL, `last_name` varchar(16) NOT NULL, `gender` char(1) NOT NULL, `hire_date` date NOT NULL, 只有年月日 PRIMARY KEY (`emp_no`));

所以同一入职的或许有很多人,order by files asc limit 1 是错误的
最晚入职的时间是最大的

select * from employees where hire_date = (select max(hire_date) from employees );
--------------------------------------------------------------------

mysql的日期类型分析
create table student(
    id int,
    name char(6),
    born_year year,
    birth_date date,
    class_time time,
    reg_time datetime
);

insert into student values
(1,‘egon‘,now(),now(),now(),now());

insert into student values
(2,‘alex‘,"1997","1997-12-12","12:12:12","2017-12-12 12:12:12");
 

2、查找入职员工时间排名倒数第三的员工所有信息

CREATE TABLE `employees` (
`emp_no` int(11) NOT NULL,
`birth_date` date NOT NULL,
`first_name` varchar(14) NOT NULL,
`last_name` varchar(16) NOT NULL,
`gender` char(1) NOT NULL,
`hire_date` date NOT NULL,
PRIMARY KEY (`emp_no`));
select * from employees where hire_date = (select hire_date from employees order by hire_date desc limit 2,1 );

注意limit 后面的 (n,m) n指索引 m是步长

 

sql练习题

标签:insert   font   student   create   ima   datetime   into   时间   倒数   

人气教程排行