标签:where tab var varchar primary select ast last not
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 max(hire_date) FROM employees); -- 最晚入职的员工不一定是一个
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 2,1表示从第2+1条记录开始,取1条记录
标签:where tab var varchar primary select ast last not
原文地址:http://www.cnblogs.com/DianeSoHungry/p/8016338.html