1.查找最晚入职员工的所有信息
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 as em where em.hire_date = max(em.hire_date);
错的好幼稚,更改如下:
select * from employees where hire_date = (select max(hire_date) from employees);
结果显示max的格式错误,在自己电脑上的mysql上是没错的,所以应该是版本的问题,牛客的版本是3.7.9,自己的版本是5.1.45 :(
所以将答案修改为:
select * from employees order by hire_date desc limit 1;