提交 1539015a 编写于 作者: M Mars Liu

in

上级 42398a8c
...@@ -2,9 +2,14 @@ ...@@ -2,9 +2,14 @@
"node_id": "mysql-6c6789b86f714acaa76467fdf9623191", "node_id": "mysql-6c6789b86f714acaa76467fdf9623191",
"keywords": [], "keywords": [],
"children": [], "children": [],
"export": [], "export": [
"exists.json"
],
"keywords_must": [ "keywords_must": [
["mysql", "exists"] [
"mysql",
"exists"
]
], ],
"keywords_forbid": [ "keywords_forbid": [
"not exists" "not exists"
......
{
"type": "code_options",
"author": "ccat",
"source": "exists.md",
"notebook_enable": false,
"exercise_id": "8d0da43e53624d8187ac781f685f4b71"
}
\ No newline at end of file
# Exists
Joe 想从员工表
```mysql
create table employee(
id int primary key auto_increment,
dept int,
name varchar(256),
post varchar(16)
)
```
中找出所有其所在部门没有助理(post 为 `assistant`)的员工信息。由于 Joe 没有其它表的查询权限,
他只能查询员工表,并且这一次他想用 exists 实现。这个查询应该是:
## 答案
```mysql
select id, name, dept
from employee as o
where not exists(select * from employee as i where o.dept = i.dept and post='assistant');
```
## 选项
### A
```mysql
select id, name, dept
from employee as o
where exists(select * from employee as i where o.dept = i.dept and post='assistant');
```
### B
```mysql
select id, name, dept
from employee as o
where not exists(select * from employee as i where o.dept = i.dept and post='assistant');
```
### C
```mysql
select id, name, dept
from employee as o
where 'assistant' != exists(select post from employee as i);
```
### D
```mysql
select id, name, dept
from employee as o
where 'assistant' = not exists(select post from employee as i where o.dept = i.dept);
```
\ No newline at end of file
...@@ -2,9 +2,14 @@ ...@@ -2,9 +2,14 @@
"node_id": "mysql-8436069c855c4f1ead7cf11a026e004b", "node_id": "mysql-8436069c855c4f1ead7cf11a026e004b",
"keywords": [], "keywords": [],
"children": [], "children": [],
"export": [], "export": [
"in.json"
],
"keywords_must": [ "keywords_must": [
["mysql", "in"] [
"mysql",
"in"
]
], ],
"keywords_forbid": [ "keywords_forbid": [
"not in" "not in"
......
{
"type": "code_options",
"author": "ccat",
"source": "in.md",
"notebook_enable": false,
"exercise_id": "2ded48602e384fc2b5476186e8b91842"
}
\ No newline at end of file
# IN
Joe 想要从员工表
```mysql
create table employee(
id int primary key auto_increment,
dept int,
name varchar(256),
post varchar(16)
)
```
中查询出研发部(dept为'rd')和人力资源部(dept为'hr')的员工列表,这个查询应该怎么写?
## 答案
```mysql
select id, dept, name, post
from employee
where dept in ('dev', 'hr');
```
## 选项
### A
```mysql
select id, dept, name, post
from employee
where dept in (select 'dev', 'hr');
```
### B
```mysql
select id, dept, name, post
from employee
where dept in (select * from 'dev', 'hr');
```
### C
```mysql
select id, dept, name, post
from employee
where dept in ('dev' and 'hr');
```
#### D
```mysql
select id, dept, name, post
from employee
where dept in ('dev' or 'hr');
```
{
"node_id": "mysql-19bc57db42bd4615ba4f123745289407",
"keywords": [],
"children": [],
"export": [],
"keywords_must": [
["mysql", "not exists"]
],
"keywords_forbid": [],
"group": 0
}
\ No newline at end of file
...@@ -1223,21 +1223,6 @@ ...@@ -1223,21 +1223,6 @@
"group": 0 "group": 0
} }
}, },
{
"NOT EXISTS": {
"node_id": "mysql-19bc57db42bd4615ba4f123745289407",
"keywords": [],
"children": [],
"keywords_must": [
[
"mysql",
"not exists"
]
],
"keywords_forbid": [],
"group": 0
}
},
{ {
" IN": { " IN": {
"node_id": "mysql-8436069c855c4f1ead7cf11a026e004b", "node_id": "mysql-8436069c855c4f1ead7cf11a026e004b",
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册