SQL1 查找最晚入职员工的所有信息
Q:请你查找employees里最晚入职员工的所有信息,以上例子输出如下:
注意点:
-- 答案一
select * from employees where hire_date=(select max(hire_date) where empolyees);
-- 答案二
select * from employees order by hire_date desc limit 1;
答案一
+--------+------------+------------+-----------+--------+------------+
| emp_no | birth_date | first_name | last_name | gender | hire_date |
+--------+------------+------------+-----------+--------+------------+
| 10008 | 1958-02-19 | Saniya | Kalloufi | M | 1994-09-15 |
| 10012 | 1958-02-01 | Jane | KAll | M | 1994-09-15 |
+--------+------------+------------+-----------+--------+------------+
答案二
+--------+------------+------------+-----------+--------+------------+
| emp_no | birth_date | first_name | last_name | gender | hire_date |
+--------+------------+------------+-----------+--------+------------+
| 10008 | 1958-02-19 | Saniya | Kalloufi | M | 1994-09-15 |
+--------+------------+------------+-----------+--------+------------+
- 答案二没有考虑到重复的情况
- limit做限制输出那些个案的时候,是以整体数据而言的,1,2,3,而不是分完组的第一组
limit 用法——暂时想到的
select * from table1 limit start_site,num;
从表table1中选取num条数据,从start_site的索引开始
num:选取的数据条数
start_site:开始的索引位置,索引从0开始
for example:
- select * from class;
- select * from class limit 2;
- select * from class limit 1,2;