From 1539015a526d667d81f7019410c7702c82db7fa2 Mon Sep 17 00:00:00 2001 From: Mars Liu Date: Mon, 6 Jun 2022 22:34:12 +0800 Subject: [PATCH] in --- .../4.EXISTS/config.json" | 9 ++- .../4.EXISTS/exists.json" | 7 +++ .../4.EXISTS/exists.md" | 56 +++++++++++++++++++ .../5. IN/config.json" | 9 ++- .../5. IN/in.json" | 7 +++ .../5. IN/in.md" | 56 +++++++++++++++++++ .../5.NOT EXISTS/config.json" | 11 ---- .../6. NOT IN/config.json" | 0 .../config.json" | 0 data/tree.json | 15 ----- 10 files changed, 140 insertions(+), 30 deletions(-) create mode 100644 "data/2.MySQL\344\270\255\351\230\266/6.\345\255\220\346\237\245\350\257\242/4.EXISTS/exists.json" create mode 100644 "data/2.MySQL\344\270\255\351\230\266/6.\345\255\220\346\237\245\350\257\242/4.EXISTS/exists.md" rename "data/2.MySQL\344\270\255\351\230\266/6.\345\255\220\346\237\245\350\257\242/6. IN/config.json" => "data/2.MySQL\344\270\255\351\230\266/6.\345\255\220\346\237\245\350\257\242/5. IN/config.json" (70%) create mode 100644 "data/2.MySQL\344\270\255\351\230\266/6.\345\255\220\346\237\245\350\257\242/5. IN/in.json" create mode 100644 "data/2.MySQL\344\270\255\351\230\266/6.\345\255\220\346\237\245\350\257\242/5. IN/in.md" delete mode 100644 "data/2.MySQL\344\270\255\351\230\266/6.\345\255\220\346\237\245\350\257\242/5.NOT EXISTS/config.json" rename "data/2.MySQL\344\270\255\351\230\266/6.\345\255\220\346\237\245\350\257\242/7. NOT IN/config.json" => "data/2.MySQL\344\270\255\351\230\266/6.\345\255\220\346\237\245\350\257\242/6. NOT IN/config.json" (100%) rename "data/2.MySQL\344\270\255\351\230\266/6.\345\255\220\346\237\245\350\257\242/8. \345\210\227\345\255\220\346\237\245\350\257\242/config.json" => "data/2.MySQL\344\270\255\351\230\266/6.\345\255\220\346\237\245\350\257\242/7. \345\210\227\345\255\220\346\237\245\350\257\242/config.json" (100%) diff --git "a/data/2.MySQL\344\270\255\351\230\266/6.\345\255\220\346\237\245\350\257\242/4.EXISTS/config.json" "b/data/2.MySQL\344\270\255\351\230\266/6.\345\255\220\346\237\245\350\257\242/4.EXISTS/config.json" index 4723747..f6d0e3f 100644 --- "a/data/2.MySQL\344\270\255\351\230\266/6.\345\255\220\346\237\245\350\257\242/4.EXISTS/config.json" +++ "b/data/2.MySQL\344\270\255\351\230\266/6.\345\255\220\346\237\245\350\257\242/4.EXISTS/config.json" @@ -2,9 +2,14 @@ "node_id": "mysql-6c6789b86f714acaa76467fdf9623191", "keywords": [], "children": [], - "export": [], + "export": [ + "exists.json" + ], "keywords_must": [ - ["mysql", "exists"] + [ + "mysql", + "exists" + ] ], "keywords_forbid": [ "not exists" diff --git "a/data/2.MySQL\344\270\255\351\230\266/6.\345\255\220\346\237\245\350\257\242/4.EXISTS/exists.json" "b/data/2.MySQL\344\270\255\351\230\266/6.\345\255\220\346\237\245\350\257\242/4.EXISTS/exists.json" new file mode 100644 index 0000000..d676a63 --- /dev/null +++ "b/data/2.MySQL\344\270\255\351\230\266/6.\345\255\220\346\237\245\350\257\242/4.EXISTS/exists.json" @@ -0,0 +1,7 @@ +{ + "type": "code_options", + "author": "ccat", + "source": "exists.md", + "notebook_enable": false, + "exercise_id": "8d0da43e53624d8187ac781f685f4b71" +} \ No newline at end of file diff --git "a/data/2.MySQL\344\270\255\351\230\266/6.\345\255\220\346\237\245\350\257\242/4.EXISTS/exists.md" "b/data/2.MySQL\344\270\255\351\230\266/6.\345\255\220\346\237\245\350\257\242/4.EXISTS/exists.md" new file mode 100644 index 0000000..1769f29 --- /dev/null +++ "b/data/2.MySQL\344\270\255\351\230\266/6.\345\255\220\346\237\245\350\257\242/4.EXISTS/exists.md" @@ -0,0 +1,56 @@ +# 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 diff --git "a/data/2.MySQL\344\270\255\351\230\266/6.\345\255\220\346\237\245\350\257\242/6. IN/config.json" "b/data/2.MySQL\344\270\255\351\230\266/6.\345\255\220\346\237\245\350\257\242/5. IN/config.json" similarity index 70% rename from "data/2.MySQL\344\270\255\351\230\266/6.\345\255\220\346\237\245\350\257\242/6. IN/config.json" rename to "data/2.MySQL\344\270\255\351\230\266/6.\345\255\220\346\237\245\350\257\242/5. IN/config.json" index ff41677..a737033 100644 --- "a/data/2.MySQL\344\270\255\351\230\266/6.\345\255\220\346\237\245\350\257\242/6. IN/config.json" +++ "b/data/2.MySQL\344\270\255\351\230\266/6.\345\255\220\346\237\245\350\257\242/5. IN/config.json" @@ -2,9 +2,14 @@ "node_id": "mysql-8436069c855c4f1ead7cf11a026e004b", "keywords": [], "children": [], - "export": [], + "export": [ + "in.json" + ], "keywords_must": [ - ["mysql", "in"] + [ + "mysql", + "in" + ] ], "keywords_forbid": [ "not in" diff --git "a/data/2.MySQL\344\270\255\351\230\266/6.\345\255\220\346\237\245\350\257\242/5. IN/in.json" "b/data/2.MySQL\344\270\255\351\230\266/6.\345\255\220\346\237\245\350\257\242/5. IN/in.json" new file mode 100644 index 0000000..9eb73c2 --- /dev/null +++ "b/data/2.MySQL\344\270\255\351\230\266/6.\345\255\220\346\237\245\350\257\242/5. IN/in.json" @@ -0,0 +1,7 @@ +{ + "type": "code_options", + "author": "ccat", + "source": "in.md", + "notebook_enable": false, + "exercise_id": "2ded48602e384fc2b5476186e8b91842" +} \ No newline at end of file diff --git "a/data/2.MySQL\344\270\255\351\230\266/6.\345\255\220\346\237\245\350\257\242/5. IN/in.md" "b/data/2.MySQL\344\270\255\351\230\266/6.\345\255\220\346\237\245\350\257\242/5. IN/in.md" new file mode 100644 index 0000000..4113cc5 --- /dev/null +++ "b/data/2.MySQL\344\270\255\351\230\266/6.\345\255\220\346\237\245\350\257\242/5. IN/in.md" @@ -0,0 +1,56 @@ +# 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'); +``` diff --git "a/data/2.MySQL\344\270\255\351\230\266/6.\345\255\220\346\237\245\350\257\242/5.NOT EXISTS/config.json" "b/data/2.MySQL\344\270\255\351\230\266/6.\345\255\220\346\237\245\350\257\242/5.NOT EXISTS/config.json" deleted file mode 100644 index cfa2898..0000000 --- "a/data/2.MySQL\344\270\255\351\230\266/6.\345\255\220\346\237\245\350\257\242/5.NOT EXISTS/config.json" +++ /dev/null @@ -1,11 +0,0 @@ -{ - "node_id": "mysql-19bc57db42bd4615ba4f123745289407", - "keywords": [], - "children": [], - "export": [], - "keywords_must": [ - ["mysql", "not exists"] - ], - "keywords_forbid": [], - "group": 0 -} \ No newline at end of file diff --git "a/data/2.MySQL\344\270\255\351\230\266/6.\345\255\220\346\237\245\350\257\242/7. NOT IN/config.json" "b/data/2.MySQL\344\270\255\351\230\266/6.\345\255\220\346\237\245\350\257\242/6. NOT IN/config.json" similarity index 100% rename from "data/2.MySQL\344\270\255\351\230\266/6.\345\255\220\346\237\245\350\257\242/7. NOT IN/config.json" rename to "data/2.MySQL\344\270\255\351\230\266/6.\345\255\220\346\237\245\350\257\242/6. NOT IN/config.json" diff --git "a/data/2.MySQL\344\270\255\351\230\266/6.\345\255\220\346\237\245\350\257\242/8. \345\210\227\345\255\220\346\237\245\350\257\242/config.json" "b/data/2.MySQL\344\270\255\351\230\266/6.\345\255\220\346\237\245\350\257\242/7. \345\210\227\345\255\220\346\237\245\350\257\242/config.json" similarity index 100% rename from "data/2.MySQL\344\270\255\351\230\266/6.\345\255\220\346\237\245\350\257\242/8. \345\210\227\345\255\220\346\237\245\350\257\242/config.json" rename to "data/2.MySQL\344\270\255\351\230\266/6.\345\255\220\346\237\245\350\257\242/7. \345\210\227\345\255\220\346\237\245\350\257\242/config.json" diff --git a/data/tree.json b/data/tree.json index 4980a17..7603111 100644 --- a/data/tree.json +++ b/data/tree.json @@ -1223,21 +1223,6 @@ "group": 0 } }, - { - "NOT EXISTS": { - "node_id": "mysql-19bc57db42bd4615ba4f123745289407", - "keywords": [], - "children": [], - "keywords_must": [ - [ - "mysql", - "not exists" - ] - ], - "keywords_forbid": [], - "group": 0 - } - }, { " IN": { "node_id": "mysql-8436069c855c4f1ead7cf11a026e004b", -- GitLab