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 4723747805f67a06ac8cdc46edab0f240f243d6c..f6d0e3f2105f6041f11ef8848d846012105d2286 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 0000000000000000000000000000000000000000..d676a63a5bdd27948f9a6ca7c7ccd3ed9a5c7531 --- /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 0000000000000000000000000000000000000000..1769f298d30f29536d97dc9ffe67e1f6e3ea25ea --- /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 ff41677b56cc9339def16dabd017f1d2a198733d..a7370332622cad746bab13b4e68e2938987110ba 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 0000000000000000000000000000000000000000..9eb73c2410614a0987bde7b7427826dcd992ac0c --- /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 0000000000000000000000000000000000000000..4113cc5d079df09a0824f6336100e7c848fed673 --- /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 cfa289802fa4c5f6872e8ee6aeea78ff9bf2a3d2..0000000000000000000000000000000000000000 --- "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 4980a1739c24f8cd51a1b8c754ff82ae2de7dcc7..7603111d3695b12f2a2d8d26776ba3e3ee63a2f4 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",