From 42398a8cc6afeff95683816229e66d4e7a802ef2 Mon Sep 17 00:00:00 2001 From: Mars Liu Date: Mon, 6 Jun 2022 21:30:42 +0800 Subject: [PATCH] all --- .../2. ANY/any.json" | 7 +++ .../2. ANY/any.md" | 50 +++++++++++++++++ .../2. ANY/config.json" | 15 ++++- .../3.ALL/all.json" | 7 +++ .../3.ALL/all.md" | 55 +++++++++++++++++++ .../3.ALL/config.json" | 9 ++- data/tree.json | 10 +++- 7 files changed, 146 insertions(+), 7 deletions(-) create mode 100644 "data/2.MySQL\344\270\255\351\230\266/6.\345\255\220\346\237\245\350\257\242/2. ANY/any.json" create mode 100644 "data/2.MySQL\344\270\255\351\230\266/6.\345\255\220\346\237\245\350\257\242/2. ANY/any.md" create mode 100644 "data/2.MySQL\344\270\255\351\230\266/6.\345\255\220\346\237\245\350\257\242/3.ALL/all.json" create mode 100644 "data/2.MySQL\344\270\255\351\230\266/6.\345\255\220\346\237\245\350\257\242/3.ALL/all.md" diff --git "a/data/2.MySQL\344\270\255\351\230\266/6.\345\255\220\346\237\245\350\257\242/2. ANY/any.json" "b/data/2.MySQL\344\270\255\351\230\266/6.\345\255\220\346\237\245\350\257\242/2. ANY/any.json" new file mode 100644 index 0000000..831e426 --- /dev/null +++ "b/data/2.MySQL\344\270\255\351\230\266/6.\345\255\220\346\237\245\350\257\242/2. ANY/any.json" @@ -0,0 +1,7 @@ +{ + "type": "code_options", + "author": "ccat", + "source": "any.md", + "notebook_enable": false, + "exercise_id": "3eaab3e2a9cd45e2ab238e6943609861" +} \ 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/2. ANY/any.md" "b/data/2.MySQL\344\270\255\351\230\266/6.\345\255\220\346\237\245\350\257\242/2. ANY/any.md" new file mode 100644 index 0000000..85ca02a --- /dev/null +++ "b/data/2.MySQL\344\270\255\351\230\266/6.\345\255\220\346\237\245\350\257\242/2. ANY/any.md" @@ -0,0 +1,50 @@ +# 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 diff --git "a/data/2.MySQL\344\270\255\351\230\266/6.\345\255\220\346\237\245\350\257\242/2. ANY/config.json" "b/data/2.MySQL\344\270\255\351\230\266/6.\345\255\220\346\237\245\350\257\242/2. ANY/config.json" index 743f950..effbfe6 100644 --- "a/data/2.MySQL\344\270\255\351\230\266/6.\345\255\220\346\237\245\350\257\242/2. ANY/config.json" +++ "b/data/2.MySQL\344\270\255\351\230\266/6.\345\255\220\346\237\245\350\257\242/2. ANY/config.json" @@ -1,10 +1,19 @@ { "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 diff --git "a/data/2.MySQL\344\270\255\351\230\266/6.\345\255\220\346\237\245\350\257\242/3.ALL/all.json" "b/data/2.MySQL\344\270\255\351\230\266/6.\345\255\220\346\237\245\350\257\242/3.ALL/all.json" new file mode 100644 index 0000000..34912fb --- /dev/null +++ "b/data/2.MySQL\344\270\255\351\230\266/6.\345\255\220\346\237\245\350\257\242/3.ALL/all.json" @@ -0,0 +1,7 @@ +{ + "type": "code_options", + "author": "ccat", + "source": "all.md", + "notebook_enable": false, + "exercise_id": "f2a50fcc0b8d4417a69b956c26eeed7a" +} \ 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/3.ALL/all.md" "b/data/2.MySQL\344\270\255\351\230\266/6.\345\255\220\346\237\245\350\257\242/3.ALL/all.md" new file mode 100644 index 0000000..a77e4ca --- /dev/null +++ "b/data/2.MySQL\344\270\255\351\230\266/6.\345\255\220\346\237\245\350\257\242/3.ALL/all.md" @@ -0,0 +1,55 @@ +# 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 diff --git "a/data/2.MySQL\344\270\255\351\230\266/6.\345\255\220\346\237\245\350\257\242/3.ALL/config.json" "b/data/2.MySQL\344\270\255\351\230\266/6.\345\255\220\346\237\245\350\257\242/3.ALL/config.json" index d8fe1f7..25846b8 100644 --- "a/data/2.MySQL\344\270\255\351\230\266/6.\345\255\220\346\237\245\350\257\242/3.ALL/config.json" +++ "b/data/2.MySQL\344\270\255\351\230\266/6.\345\255\220\346\237\245\350\257\242/3.ALL/config.json" @@ -2,9 +2,14 @@ "node_id": "mysql-87c2d9bc921643aabfd1b12b964ef557", "keywords": [], "children": [], - "export": [], + "export": [ + "all.json" + ], "keywords_must": [ - ["mysql", "all"] + [ + "mysql", + "all" + ] ], "keywords_forbid": [], "group": 0 diff --git a/data/tree.json b/data/tree.json index 6464654..4980a17 100644 --- a/data/tree.json +++ b/data/tree.json @@ -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": [], -- GitLab