1 Star 0 Fork 146

畅玩科技 / 数据库SQL实战

forked from xuthus / 数据库SQL实战 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
57.使用含有关键字exists查找未分配具体部门的员工的所有信息.md 739 Bytes
一键复制 编辑 原始数据 按行查看 历史
xuthus 提交于 2019-08-13 08:38 . revise:content revision

使用含有关键字exists查找未分配具体部门的员工的所有信息

题目描述

使用含有关键字exists查找未分配具体部门的员工的所有信息。

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`));
CREATE TABLE `dept_emp` (
`emp_no` int(11) NOT NULL,
`dept_no` char(4) NOT NULL,
`from_date` date NOT NULL,
`to_date` date NOT NULL,
PRIMARY KEY (`emp_no`,`dept_no`));

答案

select * from employees e1 where not exists (select * from dept_emp de where e1.emp_no = de.emp_no)

题解

子查询

马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
SQL
1
https://gitee.com/joyplay/Database-SQL-Actual-Combat.git
git@gitee.com:joyplay/Database-SQL-Actual-Combat.git
joyplay
Database-SQL-Actual-Combat
数据库SQL实战
master

搜索帮助

344bd9b3 5694891 D2dac590 5694891