提交 b1d3e707 编写于 作者: M Mars Liu

clean

上级 cb34344a
{
"type": "code_options",
"author": "ccat",
"author": "Mars Liu",
"source": "subquery.md",
"notebook_enable": false,
"exercise_id": "98e5d3cb30d94db0bfdca72995648586"
"exercise_id": "2fabb69f22224e48a26fec8911798ceb"
}
\ No newline at end of file
# 子查询
现有员工表
```mysql
create table employee
(
id int primary key auto_increment,
name varchar(256),
dept varchar(256),
salary decimal(12, 4)
)
```
我们希望找出比销售部(dept 为 sale)工资最高的员工工资更高的那部分人,查询出他们的完整信息,下面哪一项可以满足要求?
## 答案
```mysql
select id, name, dept, salary
from employee
where salary > (select max(salary)
from employee
where dept = 'sale')
```
## 选项
### A
```mysql
select id, name, dept, salary
from employee
where dept = 'sale'
group by dept
having salary > max(salary)
```
### B
```mysql
select l.id, l.name, l.dept, l.salary
from employee as l
join employee as r on l.salary > max(r.salary)
where r.dept = 'sale'
group by r.dept
```
### C
```mysql
select id, name, dept, salary
from employee
having salary > (select max(salary) from employee where dept = 'sale')
```
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册