提交 42398a8c 编写于 作者: M Mars Liu

all

上级 785557c9
{
"type": "code_options",
"author": "ccat",
"source": "any.md",
"notebook_enable": false,
"exercise_id": "3eaab3e2a9cd45e2ab238e6943609861"
}
\ No newline at end of file
# ANY
Joe 想要从员工表
```mysql
create table employee(
id int primary key auto_increment,
name varchar(256),
dept varchar(256),
salary decimal(12, 4)
);
```
构造一个员工列表,排除每个部门最高工资的员工。这个查询可以怎样写?
## 答案
```mysql
select id, name, dept, salary
from employee as o
where o.salary < any(select salary from employee as i where i.dept=o.dept)
```
## 选项
### A
```mysql
select id, name, dept, salary
from employee as o
join employee as i on o.dept = i.dept and o.salary < i.salary
```
### B
```mysql
select o.id, o.name, o.dept, o.salary
from employee as o
left join employee as i on o.dept = i.dept and o.salary < i.salary
where i.id is null;
```
### C
```mysql
select o.id, o.name, o.dept, o.salary
from employee as o
left join employee as i on o.dept = i.dept and o.salary < i.salary
where i.id is not null;
```
\ No newline at end of file
{
"node_id": "mysql-6bb279fa10fa4633a3af51ff7001f5ce",
"keywords": ["subquery", "子查询", "any"],
"keywords": [
"subquery",
"子查询",
"any"
],
"children": [],
"export": [],
"export": [
"any.json"
],
"keywords_must": [
["mysql", "any"]
[
"mysql",
"any"
]
],
"keywords_forbid": [],
"group": 0
......
{
"type": "code_options",
"author": "ccat",
"source": "all.md",
"notebook_enable": false,
"exercise_id": "f2a50fcc0b8d4417a69b956c26eeed7a"
}
\ No newline at end of file
# ALL
Joe 想从员工表
```mysql
create table employee(
id int primary key auto_increment,
dept int,
name varchar(256),
post varchar(16)
)
```
中找出所有其所在部门没有助理(post 为 `assistant`)的员工信息。由于 Joe 没有其它表的查询权限,他只能查询员工表,这个查询应该是:
## 答案
```mysql
select id, name, dept
from employee as o
where 'assistant' != all(select post from employee as i where o.dept = i.dept);
```
## 选项
### A
```mysql
select id, name, dept
from employee as o
where 'assistant' = all(select post from employee as i where o.dept = i.dept);
```
### B
```mysql
select id, name, dept
from employee as o
where 'assistant' != all(select post from employee as i where o.dept = i.dept);
```
### C
```mysql
select id, name, dept
from employee as o
where 'assistant' != all(select post from employee as i);
```
### D
```mysql
select id, name, dept
from employee as o
where 'assistant' != ANY(select post from employee as i where o.dept = i.dept);
```
\ No newline at end of file
......@@ -2,9 +2,14 @@
"node_id": "mysql-87c2d9bc921643aabfd1b12b964ef557",
"keywords": [],
"children": [],
"export": [],
"export": [
"all.json"
],
"keywords_must": [
["mysql", "all"]
[
"mysql",
"all"
]
],
"keywords_forbid": [],
"group": 0
......
......@@ -1036,7 +1036,10 @@
{
" RIGHT JOIN": {
"node_id": "mysql-7c2331eea3e84eef9464ad4d7c03e2de",
"keywords": [],
"keywords": [
"right join",
"右连接"
],
"children": [],
"keywords_must": [
[
......@@ -2487,7 +2490,10 @@
{
" PT-QUERY-DIGEST分析查询": {
"node_id": "mysql-626f1ca763b344558b3a5eefdb4885a2",
"keywords": [],
"keywords": [
"pt-query-digest",
"优化"
],
"children": [],
"keywords_must": [],
"keywords_forbid": [],
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册