题目描述
有一个员工表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`));
请你查找employees表所有emp_no为奇数,且last_name不为Mary的员工信息,并按照hire_date逆序排列,以上例子查询结果如下:
答案详解
方法一
select * from employees where emp_no%2!=0 and last_name!='Mary' order by hire_date desc
方法二
select * from employees where emp_no%2!=0 and last_name not in( select last_name from employees where last_name='Mary' ) order by hire_date desc