SQL204. 获取所有非manager的员工emp_no
描述
emp_no | birth_date | first_name | last_name | gender | hire_date |
10001 | 1953-09-02 | Georgi | Facello | M | 1986-06-26 |
10002 | 1964-06-02 | Bezalel | Simmel | F | 1985-11-21 |
10003 | 1959-12-03 | Parto | Bamford | M | 1986-08-28 |
dept_no | emp_no | from_date | to_date |
d001 | 10002 | 1996-08-03 | 9999-01-01 |
d002 | 10003 | 1990-08-05 | 9999-01-01 |
emp_no |
10001 |
示例1
输入:
drop table if exists `dept_manager` ; drop table if exists `employees` ; CREATE TABLE `dept_manager` ( `dept_no` char(4) NOT NULL, `emp_no` int(11) NOT NULL, `from_date` date NOT NULL, `to_date` date NOT NULL, PRIMARY KEY (`emp_no`,`dept_no`)); 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 dept_manager VALUES('d001',10002,'1996-08-03','9999-01-01'); INSERT INTO dept_manager VALUES('d002',10003,'1990-08-05','9999-01-01'); INSERT INTO employees VALUES(10001,'1953-09-02','Georgi','Facello','M','1986-06-26'); INSERT INTO employees VALUES(10002,'1964-06-02','Bezalel','Simmel','F','1985-11-21'); INSERT INTO employees VALUES(10003,'1959-12-03','Parto','Bamford','M','1986-08-28');
输出:
10001
Sqlite 解法, 执行用时: 9ms, 内存消耗: 3364KB, 提交时间: 2021-09-09
select emp_no from employees where emp_no not in( select emp_no from dept_manager);
Sqlite 解法, 执行用时: 10ms, 内存消耗: 3188KB, 提交时间: 2020-07-06
select emp_no from employees where emp_no not in (select emp_no from dept_manager)
Sqlite 解法, 执行用时: 10ms, 内存消耗: 3196KB, 提交时间: 2020-10-30
select emp_no from employees where emp_no not in (select emp_no from dept_manager)
Sqlite 解法, 执行用时: 10ms, 内存消耗: 3196KB, 提交时间: 2020-07-07
SELECT emp_no FROM employees WHERE employees.emp_no NOT IN ( SELECT emp_no FROM dept_manager)
Sqlite 解法, 执行用时: 10ms, 内存消耗: 3232KB, 提交时间: 2021-08-03
select emp_no from employees where emp_no not in (select emp_no from dept_manager)