1.数据库练习limit

数据库表

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`));

插入数据

INSERT INTO employees VALUES(10008,'1958-02-19','Saniya','Kalloufi','M','1994-09-15');
INSERT INTO employees VALUES(10009,'1958-02-19','Saniya','Kalloufi','M','1993-09-15');
INSERT INTO employees VALUES(10010,'1958-02-19','Saniya','Kalloufi','M','1993-08-15');
INSERT INTO employees VALUES(10011,'1958-02-19','Saniya','Kalloufi','M','1992-09-15');

1.数据库练习limit_第1张图片
题目1:查找最晚入职员工的所有信息

SELECT * FROM employees ORDER BY hire_date DESC LIMIT 1;
SELECT * FROM employees WHERE hire_date IN(SELECT MAX(hire_date) FROM employees);

在这里插入图片描述题目2:查找入职员工时间排名倒数第三的员工所有信息
由于数据库表的查询默认是从小到大。所以不用加asc

SELECT * FROM employees ORDER BY hire_date LIMIT 2,1;

在这里插入图片描述

你可能感兴趣的:(数据库练习)