diff --git "a/data/1.MySQL\345\210\235\351\230\266/2.\345\256\211\350\243\205\345\222\214\347\231\273\345\275\225/2.\347\231\273\345\275\225/prepare.md" "b/data/1.MySQL\345\210\235\351\230\266/2.\345\256\211\350\243\205\345\222\214\347\231\273\345\275\225/2.\347\231\273\345\275\225/prepare.md" index ad32a0e7e9abd27900afbb6bc4ca45c063c62ce0..d562db26a968dd6b0e9f5ff0412911ffe5782b60 100644 --- "a/data/1.MySQL\345\210\235\351\230\266/2.\345\256\211\350\243\205\345\222\214\347\231\273\345\275\225/2.\347\231\273\345\275\225/prepare.md" +++ "b/data/1.MySQL\345\210\235\351\230\266/2.\345\256\211\350\243\205\345\222\214\347\231\273\345\275\225/2.\347\231\273\345\275\225/prepare.md" @@ -25,8 +25,13 @@ mysql mysql ``` 创建数据库用户 joe 并授权: ```sql -create user 'joe'@'localhost' identified by 'joe'; -grant all privileges on *.* to `joe`@`localhost`; +create user + 'joe'@'localhost' + identified by 'joe'; + +grant all privileges + on *.* to `joe`@`localhost`; + flush privileges ; ``` @@ -41,7 +46,9 @@ mysql mysql ``` 为 joe 授权 ```sql -grant all privileges on *.* to joe; +grant all + privileges on *.* to joe; + flush privileges ; ``` @@ -55,7 +62,9 @@ mysql mysql 为 joe 授权 ```sql -grant all privileges on *.* to joe; +grant all + privileges on *.* to joe; + flush privileges ; ``` @@ -68,7 +77,10 @@ mysql mysql 创建数据库用户 joe ```sql -create user 'joe'@'localhost' identified by 'joe'; +create user + 'joe'@'localhost' + identified by 'joe'; + flush privileges ; ``` @@ -81,7 +93,12 @@ mysql mysql ``` 创建数据库用户 joe 并授权: ```sql -create user 'joe'@'%' identified by 'joe'; -grant all privileges on *.* to joe; +create user + 'joe'@'%' + identified by 'joe'; + +grant all + privileges on *.* to joe; + flush privileges ; ``` diff --git "a/data/1.MySQL\345\210\235\351\230\266/5.\346\225\260\346\215\256\344\277\256\346\224\271/1.\346\217\222\345\205\245/config.json" "b/data/1.MySQL\345\210\235\351\230\266/5.\346\225\260\346\215\256\344\277\256\346\224\271/1.\346\217\222\345\205\245/config.json" index 92b180e51f792f3e8fbe68d6301813853555efd9..e2a1bd612534cb4e525869734994a7d3b4fb86b3 100644 --- "a/data/1.MySQL\345\210\235\351\230\266/5.\346\225\260\346\215\256\344\277\256\346\224\271/1.\346\217\222\345\205\245/config.json" +++ "b/data/1.MySQL\345\210\235\351\230\266/5.\346\225\260\346\215\256\344\277\256\346\224\271/1.\346\217\222\345\205\245/config.json" @@ -1,12 +1,18 @@ { "node_id": "mysql-fcca525ab0f04f16834ded9b2b3f38a4", - "keywords": ["insert", "插入"], + "keywords": [ + "insert", + "插入" + ], "children": [], "export": [ "insert.json" ], "keywords_must": [ - ["mysql", "插入"] + [ + "mysql", + "插入" + ] ], "keywords_forbid": [], "group": 1 diff --git "a/data/1.MySQL\345\210\235\351\230\266/5.\346\225\260\346\215\256\344\277\256\346\224\271/1.\346\217\222\345\205\245/insert.md" "b/data/1.MySQL\345\210\235\351\230\266/5.\346\225\260\346\215\256\344\277\256\346\224\271/1.\346\217\222\345\205\245/insert.md" index 56258b1debe899d59cb9b0fff8d2925aae86b5d5..3b9e524c4946d0cfb84e4bc9db1cb900c70f6675 100644 --- "a/data/1.MySQL\345\210\235\351\230\266/5.\346\225\260\346\215\256\344\277\256\346\224\271/1.\346\217\222\345\205\245/insert.md" +++ "b/data/1.MySQL\345\210\235\351\230\266/5.\346\225\260\346\215\256\344\277\256\346\224\271/1.\346\217\222\345\205\245/insert.md" @@ -26,8 +26,24 @@ create unique index idx_book_isbn on book(isbn); ## 答案 ```sql -insert into book(title, price, isbn, publish_at) select 'a book title', 25.4, 'xx-xxxx-xxxx', '2019-12-1'; -insert into book(title, price, isbn, publish_at) select 'a other book title', 25.4, 'yy-yyyy-xxxx', '2019-12-1'; +insert into book( + title, + price, + isbn, + publish_at) + select 'a book title', + 25.4, + 'xx-xxxx-xxxx', + '2019-12-1'; + +insert into book(title, + price, + isbn, + publish_at) + select 'a other book title', + 25.4, + 'yy-yyyy-xxxx', + '2019-12-1'; ``` ## 选项 @@ -35,27 +51,83 @@ insert into book(title, price, isbn, publish_at) select 'a other book title', 25 ### 唯一键冲突 ```sql -insert into book(title, price, isbn, publish_at) select 'a book title', 25.4, 'xx-xxxx-xxxx', '2019-12-1'; -insert into book(title, price, isbn, publish_at) select 'a other book title', 35.4, 'xx-xxxx-xxxx', '2019-12-1'; +insert into book(title, + price, + isbn, + publish_at) + select 'a book title', + 25.4, + 'xx-xxxx-xxxx', + '2019-12-1'; + +insert into book(title, + price, + isbn, + publish_at) + select 'a other book title', + 35.4, + 'xx-xxxx-xxxx', + '2019-12-1'; ``` ### 缺少必要的列 ```sql -insert into book(price, isbn, publish_at) select 25.4, 'xx-xxxx-xxxx', '2019-12-1'; -insert into book(price, isbn, publish_at) select 35.4, 'yy-yyyy-xxxx', '2019-12-1'; +insert into book(price, + isbn, + publish_at) + select 25.4, + 'xx-xxxx-xxxx', + '2019-12-1'; + +insert into book(price, + isbn, + publish_at) + select 35.4, + 'yy-yyyy-xxxx', + '2019-12-1'; ``` ### 类型错误 ```sql -insert into book(title, price, isbn, publish_at) select 'a book title', 'unknown', 'xx-xxxx-xxxx', '2019-12-1'; -insert into book(title, price, isbn, publish_at) select 'a other book title', 'unknown', 'xx-xxxx-xxxx', '2019-12-1'; +insert into book(title, + price, + isbn, + publish_at) + select 'a book title', + 'unknown', + 'xx-xxxx-xxxx', + '2019-12-1'; + +insert into book(title, + price, + isbn, + publish_at) + select 'a other book title', + 'unknown', + 'xx-xxxx-xxxx', + '2019-12-1'; ``` ### 违反非空约束 ```sql -insert into book(title, price, isbn, publish_at) select null, 'unknown', 'xx-xxxx-xxxx', '2019-12-1'; -insert into book(title, price, isbn, publish_at) select null, 'unknown', 'xx-xxxx-xxxx', '2019-12-1'; +insert into book(title, + price, + isbn, + publish_at) + select null, + 'unknown', + 'xx-xxxx-xxxx', + '2019-12-1'; + +insert into book(title, + price, + isbn, + publish_at) + select null, + 'unknown', + 'xx-xxxx-xxxx', + '2019-12-1'; ``` diff --git "a/data/1.MySQL\345\210\235\351\230\266/5.\346\225\260\346\215\256\344\277\256\346\224\271/2.\344\277\256\346\224\271/update.md" "b/data/1.MySQL\345\210\235\351\230\266/5.\346\225\260\346\215\256\344\277\256\346\224\271/2.\344\277\256\346\224\271/update.md" index a1d73279ebf455eb72e04713708b0092c6431ba5..dfa92e1d98c83620bec1f3c888e457ccc8513a82 100644 --- "a/data/1.MySQL\345\210\235\351\230\266/5.\346\225\260\346\215\256\344\277\256\346\224\271/2.\344\277\256\346\224\271/update.md" +++ "b/data/1.MySQL\345\210\235\351\230\266/5.\346\225\260\346\215\256\344\277\256\346\224\271/2.\344\277\256\346\224\271/update.md" @@ -24,7 +24,9 @@ Joe 希望修改销售部(dept 字段为 sale)员工 Dora Muk 的工资,将其 ## 答案 ```sql -update employee set salary = salary + 1000 where dept = 'sale' and name = 'Dora Muk'; +update employee set + salary = salary + 1000 +where dept = 'sale' and name = 'Dora Muk'; ``` ## 选项 @@ -32,19 +34,23 @@ update employee set salary = salary + 1000 where dept = 'sale' and name = 'Dora ### 过滤条件不严谨 ```sql -update employee set salary = salary + 1000 where name = 'Dora Muk'; +update employee set + salary = salary + 1000 +where name = 'Dora Muk'; ``` ### 缺少过滤条件 ```sql -update employee set salary = salary + 1000; +update employee set + salary = salary + 1000; ``` ### 错误的赋值语句 ```sql -update employee set salary += 1000; +update employee set + salary += 1000; ``` diff --git "a/data/1.MySQL\345\210\235\351\230\266/5.\346\225\260\346\215\256\344\277\256\346\224\271/3.\345\210\240\351\231\244/delete.md" "b/data/1.MySQL\345\210\235\351\230\266/5.\346\225\260\346\215\256\344\277\256\346\224\271/3.\345\210\240\351\231\244/delete.md" index 7571ad4998992accc93719b2dbdfc34352420691..3e17d3e056ecce206bfda86b6bad6492ea0363b7 100644 --- "a/data/1.MySQL\345\210\235\351\230\266/5.\346\225\260\346\215\256\344\277\256\346\224\271/3.\345\210\240\351\231\244/delete.md" +++ "b/data/1.MySQL\345\210\235\351\230\266/5.\346\225\260\346\215\256\344\277\256\346\224\271/3.\345\210\240\351\231\244/delete.md" @@ -4,14 +4,14 @@ ```sql create table orders ( - id int primary key auto_increment, - item_id int, - amount int, - unit_price decimal(12, 4), - price decimal(12, 4), - description varchar(2000), - ts timestamp default now(), - deal bool default false + id int primary key auto_increment, + item_id int, + amount int, + unit_price decimal(12, 4), + price decimal(12, 4), + description varchar(2000), + ts timestamp default now(), + deal bool default false ); ``` @@ -60,14 +60,14 @@ from orders; ```sql drop table orders; create table if not exists orders ( - id int primary key auto_increment, - item_id int, - amount int, - unit_price decimal(12, 4), - price decimal(12, 4), - description varchar(2000), - ts timestamp default now(), - deal bool default false + id int primary key auto_increment, + item_id int, + amount int, + unit_price decimal(12, 4), + price decimal(12, 4), + description varchar(2000), + ts timestamp default now(), + deal bool default false ); ``` diff --git "a/data/1.MySQL\345\210\235\351\230\266/6.\346\225\260\346\215\256\346\237\245\350\257\242/1.SELECT/config.json" "b/data/1.MySQL\345\210\235\351\230\266/6.\346\225\260\346\215\256\346\237\245\350\257\242/1.SELECT/config.json" index 42d0c328df954a4f5e69edaec6c8098ed7ba2acd..cb558acf0b46727e816bae281d8935a9e7ce304f 100644 --- "a/data/1.MySQL\345\210\235\351\230\266/6.\346\225\260\346\215\256\346\237\245\350\257\242/1.SELECT/config.json" +++ "b/data/1.MySQL\345\210\235\351\230\266/6.\346\225\260\346\215\256\346\237\245\350\257\242/1.SELECT/config.json" @@ -1,12 +1,18 @@ { "node_id": "mysql-f5527eae7f3148108c92ff99a6d4ed4a", - "keywords": ["查询", "select"], + "keywords": [ + "查询", + "select" + ], "children": [], "export": [ "select.json" ], "keywords_must": [ - ["mysql", "select"] + [ + "mysql", + "select" + ] ], "keywords_forbid": [], "group": 1 diff --git "a/data/1.MySQL\345\210\235\351\230\266/6.\346\225\260\346\215\256\346\237\245\350\257\242/1.SELECT/select.md" "b/data/1.MySQL\345\210\235\351\230\266/6.\346\225\260\346\215\256\346\237\245\350\257\242/1.SELECT/select.md" index cb25e6d5d2d7f23bdb2944bc7fc9987f02874e92..e66aa5938efb70a0548f7f78eda0991ad6ab3864 100644 --- "a/data/1.MySQL\345\210\235\351\230\266/6.\346\225\260\346\215\256\346\237\245\350\257\242/1.SELECT/select.md" +++ "b/data/1.MySQL\345\210\235\351\230\266/6.\346\225\260\346\215\256\346\237\245\350\257\242/1.SELECT/select.md" @@ -39,7 +39,9 @@ select * from employee where dept = 'hr'; ### D ```sql -select id, name, dept, salary from employee where salary > 10000; +select id, name, dept, salary +from employee +where salary > 10000; ``` ### E diff --git "a/data/1.MySQL\345\210\235\351\230\266/6.\346\225\260\346\215\256\346\237\245\350\257\242/2.WHERE/config.json" "b/data/1.MySQL\345\210\235\351\230\266/6.\346\225\260\346\215\256\346\237\245\350\257\242/2.WHERE/config.json" index 1fa83289e27b9852fd38a871d965cca7ad150b5d..cdd0e3ee604c5bde7d5776a873f2f6f19df73e3b 100644 --- "a/data/1.MySQL\345\210\235\351\230\266/6.\346\225\260\346\215\256\346\237\245\350\257\242/2.WHERE/config.json" +++ "b/data/1.MySQL\345\210\235\351\230\266/6.\346\225\260\346\215\256\346\237\245\350\257\242/2.WHERE/config.json" @@ -1,12 +1,19 @@ { "node_id": "mysql-91cc9c73e58945d3ba654370a057a1c7", - "keywords": ["查询", "select", "where"], + "keywords": [ + "查询", + "select", + "where" + ], "children": [], "export": [ "where.json" ], "keywords_must": [ - ["mysql", "where"] + [ + "mysql", + "where" + ] ], "keywords_forbid": [], "group": 1 diff --git "a/data/1.MySQL\345\210\235\351\230\266/6.\346\225\260\346\215\256\346\237\245\350\257\242/2.WHERE/where.md" "b/data/1.MySQL\345\210\235\351\230\266/6.\346\225\260\346\215\256\346\237\245\350\257\242/2.WHERE/where.md" index 4b282d61c0e7ca8624f1b7d6f0b444bd0e6bbd6d..816d9b572824d712543ca404a585adb5be6ce6ba 100644 --- "a/data/1.MySQL\345\210\235\351\230\266/6.\346\225\260\346\215\256\346\237\245\350\257\242/2.WHERE/where.md" +++ "b/data/1.MySQL\345\210\235\351\230\266/6.\346\225\260\346\215\256\346\237\245\350\257\242/2.WHERE/where.md" @@ -40,7 +40,9 @@ where date(ts) = '2022-05-25' ```sql select id -from (select * from orders where date(ts) = '2022-05-25') as o +from (select * + from orders + where date(ts) = '2022-05-25') as o where unit_prise < 20; ``` @@ -58,7 +60,8 @@ where date(ts) = '2022-05-25' ```sql select id from orders -if date(ts) = '2022-05-25' or unit_prise < 20; +if date(ts) = '2022-05-25' + or unit_prise < 20; ``` ### D diff --git "a/data/1.MySQL\345\210\235\351\230\266/6.\346\225\260\346\215\256\346\237\245\350\257\242/3.\350\277\220\347\256\227\347\254\246/config.json" "b/data/1.MySQL\345\210\235\351\230\266/6.\346\225\260\346\215\256\346\237\245\350\257\242/3.\350\277\220\347\256\227\347\254\246/config.json" index 12ff25b8215ea920b9fc82b925ac700495238c7b..b38772881d142f12598621233389693f138c8b17 100644 --- "a/data/1.MySQL\345\210\235\351\230\266/6.\346\225\260\346\215\256\346\237\245\350\257\242/3.\350\277\220\347\256\227\347\254\246/config.json" +++ "b/data/1.MySQL\345\210\235\351\230\266/6.\346\225\260\346\215\256\346\237\245\350\257\242/3.\350\277\220\347\256\227\347\254\246/config.json" @@ -9,7 +9,10 @@ "geo.json" ], "keywords_must": [ - ["mysql", "运算符"] + [ + "mysql", + "运算符" + ] ], "keywords_forbid": [], "group": 1 diff --git "a/data/1.MySQL\345\210\235\351\230\266/6.\346\225\260\346\215\256\346\237\245\350\257\242/3.\350\277\220\347\256\227\347\254\246/geo.md" "b/data/1.MySQL\345\210\235\351\230\266/6.\346\225\260\346\215\256\346\237\245\350\257\242/3.\350\277\220\347\256\227\347\254\246/geo.md" index 1bc5e9690dba7d956497f5be4f1d71bf3d7e7c82..a8fb1e9c63f38316a81edc80bd12b16127d68a26 100644 --- "a/data/1.MySQL\345\210\235\351\230\266/6.\346\225\260\346\215\256\346\237\245\350\257\242/3.\350\277\220\347\256\227\347\254\246/geo.md" +++ "b/data/1.MySQL\345\210\235\351\230\266/6.\346\225\260\346\215\256\346\237\245\350\257\242/3.\350\277\220\347\256\227\347\254\246/geo.md" @@ -22,7 +22,8 @@ create table points( ## 答案 ```sql -select id, sqrt(x^2 + y^2) from points; +select id, sqrt(x^2 + y^2) +from points; ``` ## 选项 @@ -30,23 +31,30 @@ select id, sqrt(x^2 + y^2) from points; ### A ```sql -select sqrt(vx+vy) from (select x^2 as vx, y^2 as vy from points) as t; +select sqrt(vx+vy) +from ( + select x^2 as vx, y^2 as vy + from points) as t; ``` ### B ```sql -select sqrt(vx + vy) from points where x^2 as vx, y^2 as vy ; +select sqrt(vx + vy) +from points +where x^2 as vx, y^2 as vy ; ``` ### C ```sql -select id + sqrt(x^2 + y^2) from points; +select id + sqrt(x^2 + y^2) +from points; ``` ### D ```sql -select id || sqrt(x^2 + y^2) from points; +select id || sqrt(x^2 + y^2) +from points; ``` \ No newline at end of file diff --git "a/data/2.MySQL\344\270\255\351\230\266/1.\346\225\260\346\215\256\345\272\223\347\273\204\346\210\220/3.\345\255\230\345\202\250\350\277\207\347\250\213\345\222\214\345\207\275\346\225\260/create_procedure.md" "b/data/2.MySQL\344\270\255\351\230\266/1.\346\225\260\346\215\256\345\272\223\347\273\204\346\210\220/3.\345\255\230\345\202\250\350\277\207\347\250\213\345\222\214\345\207\275\346\225\260/create_procedure.md" index 2f663f7b9a058a02f93968bde2ad2e86cf59a155..3d3faaf1a0c4c14874cb0cd4f874373af3aa99cf 100644 --- "a/data/2.MySQL\344\270\255\351\230\266/1.\346\225\260\346\215\256\345\272\223\347\273\204\346\210\220/3.\345\255\230\345\202\250\350\277\207\347\250\213\345\222\214\345\207\275\346\225\260/create_procedure.md" +++ "b/data/2.MySQL\344\270\255\351\230\266/1.\346\225\260\346\215\256\345\272\223\347\273\204\346\210\220/3.\345\255\230\345\202\250\350\277\207\347\250\213\345\222\214\345\207\275\346\225\260/create_procedure.md" @@ -14,7 +14,10 @@ Joe 希望这个计算更紧凑一些,在已经有 individual_income_tax 的 ## 答案 ```sql -create procedure sp_idt(in salary decimal(12, 4), out tax decimal(12, 4), out take_home decimal(12, 4)) +create procedure sp_idt( + in salary decimal(12, 4), + out tax decimal(12, 4), + out take_home decimal(12, 4)) begin set tax = individual_income_tax(salary); set take_home = salary - tax; @@ -26,7 +29,9 @@ end; ### A ```sql -create procedure sp_idt(salary decimal(12, 4)) returns (tax decimal(12, 4), take_home decimal(12, 4)) +create procedure sp_idt(salary decimal(12, 4)) + returns (tax decimal(12, 4), + take_home decimal(12, 4)) begin set tax = individual_income_tax(salary); set take_home = salary - tax; @@ -37,7 +42,8 @@ end; ```sql -create procedure sp_idt(salary decimal(12, 4)) returns (decimal(12, 4), decimal(12, 4)) +create procedure sp_idt(salary decimal(12, 4)) + returns (decimal(12, 4), decimal(12, 4)) begin declare tax, take_home decimal(12, 4); set tax = individual_income_tax(salary); diff --git "a/data/2.MySQL\344\270\255\351\230\266/1.\346\225\260\346\215\256\345\272\223\347\273\204\346\210\220/5. \350\247\246\345\217\221\345\231\250/audit.md" "b/data/2.MySQL\344\270\255\351\230\266/1.\346\225\260\346\215\256\345\272\223\347\273\204\346\210\220/5. \350\247\246\345\217\221\345\231\250/audit.md" index befab47166a8034d3a8a88fd6c5a35c88ccf9912..adb11e82566609492d13ea16dc114aed93e5869d 100644 --- "a/data/2.MySQL\344\270\255\351\230\266/1.\346\225\260\346\215\256\345\272\223\347\273\204\346\210\220/5. \350\247\246\345\217\221\345\231\250/audit.md" +++ "b/data/2.MySQL\344\270\255\351\230\266/1.\346\225\260\346\215\256\345\272\223\347\273\204\346\210\220/5. \350\247\246\345\217\221\345\231\250/audit.md" @@ -45,13 +45,44 @@ create table orders_log ## 答案 ```sql -create trigger in_orders after insert on orders - for each row insert into orders_log(id, item_id, amount, unit_price, total, description, ts, direction) - values(NEW.id, NEW.item_id, NEW.amount, NEW.unit_price, NEW.total, NEW.description, NEW.ts, 'in'); - -create trigger out_orders after delete on orders - for each row insert into orders_log(id, item_id, amount, unit_price, total, description, ts, direction) - values(OLD.id, OLD.item_id, OLD.amount, OLD.unit_price, OLD.total, OLD.description, OLD.ts, 'out'); +create trigger in_orders + after insert on orders + for each row insert into orders_log( + id, + item_id, + amount, + unit_price, + total, + description, + ts, + direction) + values(NEW.id, + NEW.item_id, + NEW.amount, + NEW.unit_price, + NEW.total, + NEW.description, + NEW.ts, 'in'); + +create trigger out_orders + after delete on orders + for each row insert into orders_log( + id, + item_id, + amount, + unit_price, + total, + description, + ts, + direction) + values(OLD.id, + OLD.item_id, + OLD.amount, + OLD.unit_price, + OLD.total, + OLD.description, + OLD.ts, + 'out'); ``` ## 选项 @@ -60,8 +91,23 @@ create trigger out_orders after delete on orders ```sql create trigger in_orders after insert on orders - for each row insert into orders_log(id, item_id, amount, unit_price, total, description, ts, direction) - values(NEW.id, NEW.item_id, NEW.amount, NEW.unit_price, NEW.total, NEW.description, NEW.ts, 'in'); + for each row insert into orders_log( + id, + item_id, + amount, + unit_price, + total, + description, + ts, + direction) + values(NEW.id, + NEW.item_id, + NEW.amount, + NEW.unit_price, + NEW.total, + NEW.description, + NEW.ts, + 'in'); ``` @@ -70,8 +116,23 @@ create trigger in_orders after insert on orders ```sql create trigger out_orders after delete on orders - for each row insert into orders_log(id, item_id, amount, unit_price, total, description, ts, direction) - values(OLD.id, OLD.item_id, OLD.amount, OLD.unit_price, OLD.total, OLD.description, OLD.ts, 'out'); + for each row insert into orders_log( + id, + item_id, + amount, + unit_price, + total, + description, + ts, + direction) + values(OLD.id, + OLD.item_id, + OLD.amount, + OLD.unit_price, + OLD.total, + OLD.description, + OLD.ts, + 'out'); ``` @@ -79,17 +140,63 @@ create trigger out_orders after delete on orders ```sql create trigger in_orders after insert on orders - for each row insert into orders_log(id, item_id, amount, unit_price, total, description, ts, direction) - values(NEW.id, NEW.item_id, NEW.amount, NEW.unit_price, NEW.total, NEW.description, NEW.ts, 'in'); + for each row insert into orders_log( + id, + item_id, + amount, + unit_price, + total, + description, + ts, + direction) + values(NEW.id, + NEW.item_id, + NEW.amount, + NEW.unit_price, + NEW.total, + NEW.description, + NEW.ts, + 'in'); + after delete on orders - for each row insert into orders_log(id, item_id, amount, unit_price, total, description, ts, direction) - values(OLD.id, OLD.item_id, OLD.amount, OLD.unit_price, OLD.total, OLD.description, OLD.ts, 'out'); + for each row insert into orders_log( + id, + item_id, + amount, + unit_price, + total, + description, + ts, + direction) + values(OLD.id, + OLD.item_id, + OLD.amount, + OLD.unit_price, + OLD.total, + OLD.description, + OLD.ts, + 'out'); ``` ### D ```sql create trigger in_orders after insert, after delete on orders - for each row insert into orders_log(id, item_id, amount, unit_price, total, description, ts, direction) - values(NEW.id, NEW.item_id, NEW.amount, NEW.unit_price, NEW.total, NEW.description, NEW.ts, 'in'); + for each row insert into orders_log( + id, + item_id, + amount, + unit_price, + total, + description, + ts, + direction) + values(NEW.id, + NEW.item_id, + NEW.amount, + NEW.unit_price, + NEW.total, + NEW.description, + NEW.ts, + 'in'); ``` \ No newline at end of file diff --git "a/data/2.MySQL\344\270\255\351\230\266/11.\347\224\250\346\210\267\345\222\214\346\235\203\351\231\220/1.\345\210\233\345\273\272\346\231\256\351\200\232\347\224\250\346\210\267/create_user.md" "b/data/2.MySQL\344\270\255\351\230\266/11.\347\224\250\346\210\267\345\222\214\346\235\203\351\231\220/1.\345\210\233\345\273\272\346\231\256\351\200\232\347\224\250\346\210\267/create_user.md" index 009aa910d66b130fedf2b46ff6413804754ab6a7..b3ab74accaf488b9fe1d1c2c155cb46d27a9cf1a 100644 --- "a/data/2.MySQL\344\270\255\351\230\266/11.\347\224\250\346\210\267\345\222\214\346\235\203\351\231\220/1.\345\210\233\345\273\272\346\231\256\351\200\232\347\224\250\346\210\267/create_user.md" +++ "b/data/2.MySQL\344\270\255\351\230\266/11.\347\224\250\346\210\267\345\222\214\346\235\203\351\231\220/1.\345\210\233\345\273\272\346\231\256\351\200\232\347\224\250\346\210\267/create_user.md" @@ -13,8 +13,11 @@ Joe 要给数据组的 John 创建一个用户,他希望John 能够从 `192.16 ## 答案 ```sql -create user 'john'@'192.168.7.42' identified by 'goods123' password expire; +create user 'john'@'192.168.7.42' + identified by 'goods123' password expire; + grant select on goods.* to 'john'@'192.168.7.42'; + flush privileges; ``` @@ -23,22 +26,31 @@ flush privileges; ### A ```sql -create user 'john'@'192.168.7.42' identified by 'goods123'; +create user 'john'@'192.168.7.42' + identified by 'goods123'; + grant select on goods.* to 'john'@'192.168.7.42'; + flush privileges; ``` ### B ```sql -create user 'john'@'192.168.7.42' identified by 'goods123'; -grant usage on goods.* to 'john'@'192.168.7.42'; +create user 'john'@'192.168.7.42' + identified by 'goods123'; + +grant usage on + goods.* to 'john'@'192.168.7.42'; + flush privileges; ``` ### C ```sql -create user 'john'@'192.168.7.42' identified by 'goods123' on database goods; +create user 'john'@'192.168.7.42' + identified by 'goods123' on database goods; + flush privileges; ``` \ No newline at end of file diff --git "a/data/2.MySQL\344\270\255\351\230\266/11.\347\224\250\346\210\267\345\222\214\346\235\203\351\231\220/1.\345\210\233\345\273\272\346\231\256\351\200\232\347\224\250\346\210\267/create_user_desc.md" "b/data/2.MySQL\344\270\255\351\230\266/11.\347\224\250\346\210\267\345\222\214\346\235\203\351\231\220/1.\345\210\233\345\273\272\346\231\256\351\200\232\347\224\250\346\210\267/create_user_desc.md" index 162815082fb4138d382b474fae48267886410c58..9a11c7a3d0cb5b535e267650c6c02c6ba7cdaf6f 100644 --- "a/data/2.MySQL\344\270\255\351\230\266/11.\347\224\250\346\210\267\345\222\214\346\235\203\351\231\220/1.\345\210\233\345\273\272\346\231\256\351\200\232\347\224\250\346\210\267/create_user_desc.md" +++ "b/data/2.MySQL\344\270\255\351\230\266/11.\347\224\250\346\210\267\345\222\214\346\235\203\351\231\220/1.\345\210\233\345\273\272\346\231\256\351\200\232\347\224\250\346\210\267/create_user_desc.md" @@ -22,31 +22,21 @@ IDENTIFIED BY '@Binghe123456'; ### A -``` 可以使用GRANT来创建用户 -``` ### B -``` 可以使用CREATE USER语句来创建用户 -``` ### C -``` CREATE USER 'binghe'@'localhost'; 创建用户名为binghe的MySQL用户,其主机名为localhost。 -``` ### D -``` 使用GRANT语句创建用户,不仅可以添加用户,而且还能为用户赋予相应的权限。 -``` ### E -``` 使用CREATE USER语句创建用户时,只是在mysql数据库下的user数据表中添加了一条记录,并没有为用户授权。 -``` \ No newline at end of file diff --git "a/data/2.MySQL\344\270\255\351\230\266/11.\347\224\250\346\210\267\345\222\214\346\235\203\351\231\220/7.\351\231\220\345\210\266\347\224\250\346\210\267\344\275\277\347\224\250\350\265\204\346\272\220/limit_action.md" "b/data/2.MySQL\344\270\255\351\230\266/11.\347\224\250\346\210\267\345\222\214\346\235\203\351\231\220/7.\351\231\220\345\210\266\347\224\250\346\210\267\344\275\277\347\224\250\350\265\204\346\272\220/limit_action.md" index be5a7a9470580f4e11654511ad44b865570ff561..ce8e9eb2ea6d4cf44bbd69d719cfd33d9c5e7dae 100644 --- "a/data/2.MySQL\344\270\255\351\230\266/11.\347\224\250\346\210\267\345\222\214\346\235\203\351\231\220/7.\351\231\220\345\210\266\347\224\250\346\210\267\344\275\277\347\224\250\350\265\204\346\272\220/limit_action.md" +++ "b/data/2.MySQL\344\270\255\351\230\266/11.\347\224\250\346\210\267\345\222\214\346\235\203\351\231\220/7.\351\231\220\345\210\266\347\224\250\346\210\267\344\275\277\347\224\250\350\265\204\346\272\220/limit_action.md" @@ -12,7 +12,8 @@ Joe 需要限制数据分析组(role analysis)的用户, 每小时查询次 ## 答案 ```sql -alter user analysis with MAX_QUERIES_PER_HOUR 10000; +alter user analysis + with MAX_QUERIES_PER_HOUR 10000; ``` ## 选项 @@ -20,24 +21,28 @@ alter user analysis with MAX_QUERIES_PER_HOUR 10000; ### A ```sql -set user analysis with MAX_QUERIES_PER_HOUR 10000; +set user analysis + with MAX_QUERIES_PER_HOUR 10000; ``` ### B ```sql -alter role analysis with MAX_QUERIES_PER_HOUR 10000; +alter role analysis + with MAX_QUERIES_PER_HOUR 10000; ``` ### C ```sql -alter role analysis with MAX_QUERIES_PER_HOUR=10000; +alter role analysis + with MAX_QUERIES_PER_HOUR=10000; ``` ### D ```sql -alter user analysis set MAX_QUERIES_PER_HOUR 10000; +alter user analysis + set MAX_QUERIES_PER_HOUR 10000; ``` diff --git "a/data/2.MySQL\344\270\255\351\230\266/2.\346\237\245\350\257\242\350\277\233\351\230\266/2. BETWEEN/between.md" "b/data/2.MySQL\344\270\255\351\230\266/2.\346\237\245\350\257\242\350\277\233\351\230\266/2. BETWEEN/between.md" index 4a42b6f78ff5eb5a2f2b51e87dc0e443d59bc01a..bb61964dbc9551e7d39a75ae8ea5b6efdfcc9d6b 100644 --- "a/data/2.MySQL\344\270\255\351\230\266/2.\346\237\245\350\257\242\350\277\233\351\230\266/2. BETWEEN/between.md" +++ "b/data/2.MySQL\344\270\255\351\230\266/2.\346\237\245\350\257\242\350\277\233\351\230\266/2. BETWEEN/between.md" @@ -24,7 +24,10 @@ create table goods( ## 答案 ```sql -SELECT * FROM goods HAVING price BETWEEN 1000 AND 2000; +SELECT * +FROM goods +HAVING price + BETWEEN 1000 AND 2000; ``` @@ -33,18 +36,25 @@ SELECT * FROM goods HAVING price BETWEEN 1000 AND 2000; ### A ```sql -SELECT * FROM goods WHERE price BETWEEN 1000 AND 2000; +SELECT * +FROM goods +WHERE price + BETWEEN 1000 AND 2000; ``` ### B ```sql -SELECT * FROM goods WHERE price >= 1000 AND price <= 2000; +SELECT * +FROM goods +WHERE price >= 1000 AND price <= 2000; ``` ### C ```sql -SELECT * FROM goods WHERE not (price < 1000 or price > 2000); +SELECT * +FROM goods +WHERE not (price < 1000 or price > 2000); ``` diff --git "a/data/2.MySQL\344\270\255\351\230\266/2.\346\237\245\350\257\242\350\277\233\351\230\266/2. BETWEEN/config.json" "b/data/2.MySQL\344\270\255\351\230\266/2.\346\237\245\350\257\242\350\277\233\351\230\266/2. BETWEEN/config.json" index 21c324ce55b85aee3f34336704ed856578be3fb4..e696abda25d276b37c24aeebb8a83aa43c26818a 100644 --- "a/data/2.MySQL\344\270\255\351\230\266/2.\346\237\245\350\257\242\350\277\233\351\230\266/2. BETWEEN/config.json" +++ "b/data/2.MySQL\344\270\255\351\230\266/2.\346\237\245\350\257\242\350\277\233\351\230\266/2. BETWEEN/config.json" @@ -1,12 +1,17 @@ { "node_id": "mysql-2296dbe96d584a52bd28a3ad5f655518", - "keywords": ["where"], + "keywords": [ + "where" + ], "children": [], "export": [ "between.json" ], "keywords_must": [ - ["mysql", "between"] + [ + "mysql", + "between" + ] ], "keywords_forbid": [], "group": 1 diff --git "a/data/2.MySQL\344\270\255\351\230\266/2.\346\237\245\350\257\242\350\277\233\351\230\266/4.DISTINCT/distinct.md" "b/data/2.MySQL\344\270\255\351\230\266/2.\346\237\245\350\257\242\350\277\233\351\230\266/4.DISTINCT/distinct.md" index 52fba35ebf0768839354b4c96258f87da5cb8038..d66299b4ac1477886dc6cc5891858ac2b76a8dd5 100644 --- "a/data/2.MySQL\344\270\255\351\230\266/2.\346\237\245\350\257\242\350\277\233\351\230\266/4.DISTINCT/distinct.md" +++ "b/data/2.MySQL\344\270\255\351\230\266/2.\346\237\245\350\257\242\350\277\233\351\230\266/4.DISTINCT/distinct.md" @@ -26,7 +26,8 @@ create table goods( ## 答案 ```sql -select count(distinct price) from goods; +select count(distinct price) +from goods; ``` ## 选项 @@ -34,23 +35,27 @@ select count(distinct price) from goods; ### A ```sql -select count(distinct *) from goods; +select count(distinct *) +from goods; ``` ### B ```sql -select distinct count(price) from goods; +select distinct count(price) +from goods; ``` ### C ```sql -select count(price) from goods; +select count(price) +from goods; ``` ### D ```sql -select distinct price from goods; +select distinct price +from goods; ``` diff --git "a/data/2.MySQL\344\270\255\351\230\266/2.\346\237\245\350\257\242\350\277\233\351\230\266/5.ORDER BY/order_by.md" "b/data/2.MySQL\344\270\255\351\230\266/2.\346\237\245\350\257\242\350\277\233\351\230\266/5.ORDER BY/order_by.md" index ae73cc91810923bf3f6636c7e6fd5108a0c97657..7cc61b7cf1fa310a5d35e5ddbddfc65494ff2460 100644 --- "a/data/2.MySQL\344\270\255\351\230\266/2.\346\237\245\350\257\242\350\277\233\351\230\266/5.ORDER BY/order_by.md" +++ "b/data/2.MySQL\344\270\255\351\230\266/2.\346\237\245\350\257\242\350\277\233\351\230\266/5.ORDER BY/order_by.md" @@ -24,7 +24,9 @@ create table employee ## 答案 ```sql -select id, name, dept, salary from employee order by dept, salary desc; +select id, name, dept, salary +from employee +order by dept, salary desc; ``` ## 选项 @@ -32,28 +34,38 @@ select id, name, dept, salary from employee order by dept, salary desc; ### A ```sql -select id, name, dept, salary from employee order by dept, salary; +select id, name, dept, salary +from employee +order by dept, salary; ``` ### B ```sql -select id, name, dept, salary from employee order by dept desc, salary desc; +select id, name, dept, salary +from employee +order by dept desc, salary desc; ``` ### C ```sql -select id, name, dept, salary from employee order by dept and salary desc; +select id, name, dept, salary +from employee +order by dept and salary desc; ``` ### D ```sql -select id, name, dept, salary from employee order by dept, salary, id, name; +select id, name, dept, salary +from employee +order by dept, salary, id, name; ``` ### E ```sql -select id, name, dept, salary from employee order by dept, salary desc; +select id, name, dept, salary +from employee +order by dept, salary desc; ``` diff --git "a/data/2.MySQL\344\270\255\351\230\266/2.\346\237\245\350\257\242\350\277\233\351\230\266/6.UNION/config.json" "b/data/2.MySQL\344\270\255\351\230\266/2.\346\237\245\350\257\242\350\277\233\351\230\266/6.UNION/config.json" index 97e0731a14f3ab1eb97ed0ab9d613f801f0ac3ea..42f889f1e2028a0d95dbff6039739271f53267d4 100644 --- "a/data/2.MySQL\344\270\255\351\230\266/2.\346\237\245\350\257\242\350\277\233\351\230\266/6.UNION/config.json" +++ "b/data/2.MySQL\344\270\255\351\230\266/2.\346\237\245\350\257\242\350\277\233\351\230\266/6.UNION/config.json" @@ -1,12 +1,17 @@ { "node_id": "mysql-b57b6c08f5f240c6a997284e4448f088", - "keywords": ["union"], + "keywords": [ + "union" + ], "children": [], "export": [ "union.json" ], "keywords_must": [ - ["mysql", "union"] + [ + "mysql", + "union" + ] ], "keywords_forbid": [], "group": 1 diff --git "a/data/2.MySQL\344\270\255\351\230\266/2.\346\237\245\350\257\242\350\277\233\351\230\266/6.UNION/union.md" "b/data/2.MySQL\344\270\255\351\230\266/2.\346\237\245\350\257\242\350\277\233\351\230\266/6.UNION/union.md" index 641f9b82ab5cec2b8dbd6cfa42e83b2c29aa1c89..10b9885fd00873b29600b22dc72e3a33d9643d76 100644 --- "a/data/2.MySQL\344\270\255\351\230\266/2.\346\237\245\350\257\242\350\277\233\351\230\266/6.UNION/union.md" +++ "b/data/2.MySQL\344\270\255\351\230\266/2.\346\237\245\350\257\242\350\277\233\351\230\266/6.UNION/union.md" @@ -12,10 +12,10 @@ create table employee( ); create table customer( - id int primary key auto_increment, - name varchar(256), - address varchar(1024), - level int + id int primary key auto_increment, + name varchar(256), + address varchar(1024), + level int -- ignore more ) diff --git "a/data/2.MySQL\344\270\255\351\230\266/2.\346\237\245\350\257\242\350\277\233\351\230\266/8. \345\210\206\351\241\265\346\237\245\350\257\242/paged.md" "b/data/2.MySQL\344\270\255\351\230\266/2.\346\237\245\350\257\242\350\277\233\351\230\266/8. \345\210\206\351\241\265\346\237\245\350\257\242/paged.md" index 01790f6a1515994e665726b7570625391c7f7ddd..f858ca5518a4e078b4421b25990355a101b45fa3 100644 --- "a/data/2.MySQL\344\270\255\351\230\266/2.\346\237\245\350\257\242\350\277\233\351\230\266/8. \345\210\206\351\241\265\346\237\245\350\257\242/paged.md" +++ "b/data/2.MySQL\344\270\255\351\230\266/2.\346\237\245\350\257\242\350\277\233\351\230\266/8. \345\210\206\351\241\265\346\237\245\350\257\242/paged.md" @@ -25,7 +25,11 @@ create table orders ## 答案 ```sql -select id, product_id, order_date, quantity, customer_id +select id, + product_id, + order_date, + quantity, + customer_id from orders where date = $1 offset $2 limit 100; @@ -36,7 +40,11 @@ offset $2 limit 100; ### 缺少 limit ```sql -select id, product_id, order_date, quantity, customer_id +select id, + product_id, + order_date, + quantity, + customer_id from orders where date = $1 offset $2; @@ -45,7 +53,11 @@ offset $2; ### 缺少 offset ```sql -select id, product_id, order_date, quantity, customer_id +select id, + product_id, + order_date, + quantity, + customer_id from orders where date = $1; ``` @@ -53,7 +65,11 @@ where date = $1; ### 结构不对 ```sql -select id, product_id, order_date, quantity, customer_id +select id, + product_id, + order_date, + quantity, + customer_id from orders where date = $1 and offset $2 and limit 100; diff --git "a/data/2.MySQL\344\270\255\351\230\266/3.\345\206\205\347\275\256\345\207\275\346\225\260/5.\345\205\266\345\256\203\345\207\275\346\225\260/convert.md" "b/data/2.MySQL\344\270\255\351\230\266/3.\345\206\205\347\275\256\345\207\275\346\225\260/5.\345\205\266\345\256\203\345\207\275\346\225\260/convert.md" index 61e4382fda398a1be458de2c603a2c8e77c35425..a0a900fa6497c4f98f02acaeda3bd23cb56e6870 100644 --- "a/data/2.MySQL\344\270\255\351\230\266/3.\345\206\205\347\275\256\345\207\275\346\225\260/5.\345\205\266\345\256\203\345\207\275\346\225\260/convert.md" +++ "b/data/2.MySQL\344\270\255\351\230\266/3.\345\206\205\347\275\256\345\207\275\346\225\260/5.\345\205\266\345\256\203\345\207\275\346\225\260/convert.md" @@ -18,7 +18,8 @@ select name from goods; ## 答案 ```sql -select convert(name using 'gb18030') from goods; +select convert(name using 'gb18030') +from goods; ``` ## 选项 @@ -27,27 +28,31 @@ select convert(name using 'gb18030') from goods; ### A ```sql -select str(name, 'gb18303') from goods; +select str(name, 'gb18303') +from goods; ``` ### B ```sql -select encode(decode(name, 'utf8mb4'), 'gb18303') from goods; +select encode(decode(name, 'utf8mb4'), 'gb18303') +from goods; ``` ### C ```sql -select convert(name from 'utf8mb4' to 'gb18303') from goods; +select convert(name from 'utf8mb4' to 'gb18303') +from goods; ``` ### D ```sql -select convert(name to 'gb18303') from goods; +select convert(name to 'gb18303') +from goods; ``` ### E diff --git "a/data/2.MySQL\344\270\255\351\230\266/4.\350\201\232\345\220\210\345\222\214\345\210\206\347\273\204/1. \350\256\241\346\225\260/count.md" "b/data/2.MySQL\344\270\255\351\230\266/4.\350\201\232\345\220\210\345\222\214\345\210\206\347\273\204/1. \350\256\241\346\225\260/count.md" index 1042a3161fc7fd9b0672b941816b9ed901d69538..e9422681d2351e63d2e9e6ce7f767bc2c4363910 100644 --- "a/data/2.MySQL\344\270\255\351\230\266/4.\350\201\232\345\220\210\345\222\214\345\210\206\347\273\204/1. \350\256\241\346\225\260/count.md" +++ "b/data/2.MySQL\344\270\255\351\230\266/4.\350\201\232\345\220\210\345\222\214\345\210\206\347\273\204/1. \350\256\241\346\225\260/count.md" @@ -17,7 +17,8 @@ mysql> select * from items; 当他执行 ```sql -select count(*), count(item) from items; +select count(*), count(item) +from items; ``` 会得到什么结果? diff --git "a/data/2.MySQL\344\270\255\351\230\266/4.\350\201\232\345\220\210\345\222\214\345\210\206\347\273\204/2. \346\261\202\345\222\214/sum.md" "b/data/2.MySQL\344\270\255\351\230\266/4.\350\201\232\345\220\210\345\222\214\345\210\206\347\273\204/2. \346\261\202\345\222\214/sum.md" index ae6ee7dea93f73be771acd693c0e5f899428ae6f..c72fd3a20e06714e36bdc5082b78aea673ba2366 100644 --- "a/data/2.MySQL\344\270\255\351\230\266/4.\350\201\232\345\220\210\345\222\214\345\210\206\347\273\204/2. \346\261\202\345\222\214/sum.md" +++ "b/data/2.MySQL\344\270\255\351\230\266/4.\350\201\232\345\220\210\345\222\214\345\210\206\347\273\204/2. \346\261\202\345\222\214/sum.md" @@ -4,14 +4,14 @@ Joe 想要得到 orders 表 ```sql create table orders ( - id int primary key auto_increment, - item_id int, - amount int, - unit_price decimal(12, 4), - total decimal(12, 4), - description varchar(2000), - ts timestamp default now(), - deal bool default false + id int primary key auto_increment, + item_id int, + amount int, + unit_price decimal(12, 4), + total decimal(12, 4), + description varchar(2000), + ts timestamp default now(), + deal bool default false ); ``` @@ -27,7 +27,9 @@ create table orders ( ## 答案 ```sql -select sum(total) from orders where deal and unit_price > 1000; +select sum(total) +from orders +where deal and unit_price > 1000; ``` ## 选项 @@ -35,17 +37,24 @@ select sum(total) from orders where deal and unit_price > 1000; ### A ```sql -select sum(total) from orders having deal and unit_price > 1000; +select sum(total) +from orders +having deal and unit_price > 1000; ``` ### B ```sql -select sum(total) from orders group by deal having unit_price > 1000; +select sum(total) +from orders +group by deal +having unit_price > 1000; ``` ### C ```sql -select sum(total) from orders order by deal and unit_price > 1000; +select sum(total) +from orders +order by deal and unit_price > 1000; ``` \ No newline at end of file diff --git "a/data/2.MySQL\344\270\255\351\230\266/4.\350\201\232\345\220\210\345\222\214\345\210\206\347\273\204/3.\346\234\200\345\260\217\345\200\274/min.md" "b/data/2.MySQL\344\270\255\351\230\266/4.\350\201\232\345\220\210\345\222\214\345\210\206\347\273\204/3.\346\234\200\345\260\217\345\200\274/min.md" index 2bef6c26aa5d0dab75217da64db9715628614ca3..eb6ef2bdd0389a119919f09ceba7d3071a64daf2 100644 --- "a/data/2.MySQL\344\270\255\351\230\266/4.\350\201\232\345\220\210\345\222\214\345\210\206\347\273\204/3.\346\234\200\345\260\217\345\200\274/min.md" +++ "b/data/2.MySQL\344\270\255\351\230\266/4.\350\201\232\345\220\210\345\222\214\345\210\206\347\273\204/3.\346\234\200\345\260\217\345\200\274/min.md" @@ -24,7 +24,9 @@ create table employee ## 答案 ```sql -select dept, min(salary) from employee group by dept; +select dept, min(salary) +from employee +group by dept; ``` ## 选项 @@ -32,17 +34,20 @@ select dept, min(salary) from employee group by dept; ### A ```sql -select dept, min(salary) from employee; +select dept, min(salary) +from employee; ``` ### B ```sql -select dept, min(salary) from employee order by dept; +select dept, min(salary) +from employee order by dept; ``` ### C ```sql -select dept, min(total) from employee; +select dept, min(total) +from employee; ``` \ No newline at end of file diff --git "a/data/2.MySQL\344\270\255\351\230\266/4.\350\201\232\345\220\210\345\222\214\345\210\206\347\273\204/5. \345\271\263\345\235\207\345\200\274/avg.md" "b/data/2.MySQL\344\270\255\351\230\266/4.\350\201\232\345\220\210\345\222\214\345\210\206\347\273\204/5. \345\271\263\345\235\207\345\200\274/avg.md" index 9bec946de9e46b326c695a5d5563c1a979709c59..af9a21473b82de58596e9f226f8b59ca632a0b89 100644 --- "a/data/2.MySQL\344\270\255\351\230\266/4.\350\201\232\345\220\210\345\222\214\345\210\206\347\273\204/5. \345\271\263\345\235\207\345\200\274/avg.md" +++ "b/data/2.MySQL\344\270\255\351\230\266/4.\350\201\232\345\220\210\345\222\214\345\210\206\347\273\204/5. \345\271\263\345\235\207\345\200\274/avg.md" @@ -24,7 +24,9 @@ create table employee ## 答案 ```sql -select dept, avg(salary) from employee group by dept; +select dept, avg(salary) +from employee +group by dept; ``` ## 选项 @@ -32,17 +34,22 @@ select dept, avg(salary) from employee group by dept; ### A ```sql -select dept, avg(salary) from employee; +select dept, avg(salary) +from employee; ``` ### B ```sql -select dept, avg(dept) from employee group by dept; +select dept, avg(dept) +from employee +group by dept; ``` ### C ```sql -select dept, avg(salary) from employee group by salary; +select dept, avg(salary) +from employee +group by salary; ``` diff --git "a/data/2.MySQL\344\270\255\351\230\266/4.\350\201\232\345\220\210\345\222\214\345\210\206\347\273\204/5. \345\271\263\345\235\207\345\200\274/config.json" "b/data/2.MySQL\344\270\255\351\230\266/4.\350\201\232\345\220\210\345\222\214\345\210\206\347\273\204/5. \345\271\263\345\235\207\345\200\274/config.json" index 7061a24e7a784f93d77bb5764205964b0ca92d94..27a53768eff2f8647508c6a1bbbc86e025fdb269 100644 --- "a/data/2.MySQL\344\270\255\351\230\266/4.\350\201\232\345\220\210\345\222\214\345\210\206\347\273\204/5. \345\271\263\345\235\207\345\200\274/config.json" +++ "b/data/2.MySQL\344\270\255\351\230\266/4.\350\201\232\345\220\210\345\222\214\345\210\206\347\273\204/5. \345\271\263\345\235\207\345\200\274/config.json" @@ -1,6 +1,9 @@ { "node_id": "mysql-11462fccf9d24d17a372d5c60af90f54", - "keywords": ["avg", "平均值"], + "keywords": [ + "avg", + "平均值" + ], "children": [], "export": [ "avg.json" diff --git "a/data/2.MySQL\344\270\255\351\230\266/4.\350\201\232\345\220\210\345\222\214\345\210\206\347\273\204/6.HAVING/config.json" "b/data/2.MySQL\344\270\255\351\230\266/4.\350\201\232\345\220\210\345\222\214\345\210\206\347\273\204/6.HAVING/config.json" index f49eae2b6bb6fbf83b4de99ebda7c06336678c52..080ccbf2cf5cd3303b172d4ade80f138352df7c7 100644 --- "a/data/2.MySQL\344\270\255\351\230\266/4.\350\201\232\345\220\210\345\222\214\345\210\206\347\273\204/6.HAVING/config.json" +++ "b/data/2.MySQL\344\270\255\351\230\266/4.\350\201\232\345\220\210\345\222\214\345\210\206\347\273\204/6.HAVING/config.json" @@ -6,7 +6,10 @@ "having.json" ], "keywords_must": [ - ["mysql", "having"] + [ + "mysql", + "having" + ] ], "keywords_forbid": [], "group": 1 diff --git "a/data/2.MySQL\344\270\255\351\230\266/4.\350\201\232\345\220\210\345\222\214\345\210\206\347\273\204/6.HAVING/having.md" "b/data/2.MySQL\344\270\255\351\230\266/4.\350\201\232\345\220\210\345\222\214\345\210\206\347\273\204/6.HAVING/having.md" index 6f2958b57ae38bf4d74bffe75c855f30586fca59..9602b2fe6b72755ac0ebfc7d81dd3d90670511e5 100644 --- "a/data/2.MySQL\344\270\255\351\230\266/4.\350\201\232\345\220\210\345\222\214\345\210\206\347\273\204/6.HAVING/having.md" +++ "b/data/2.MySQL\344\270\255\351\230\266/4.\350\201\232\345\220\210\345\222\214\345\210\206\347\273\204/6.HAVING/having.md" @@ -24,7 +24,10 @@ create table employee ## 答案 ```sql -select dept from employee group by dept having sum(salary) > 100000; +select dept +from employee +group by dept +having sum(salary) > 100000; ``` ## 选项 @@ -32,25 +35,36 @@ select dept from employee group by dept having sum(salary) > 100000; ### A ```sql -select dept from employee group by dept where sum(salary) > 100000; +select dept +from employee +group by dept where sum(salary) > 100000; ``` ### B ```sql -select dept from employee where sum(salary) > 100000 group by dept; +select dept +from employee +where sum(salary) > 100000 +group by dept; ``` ### C ```sql -select dept from employee where sum(salary) > 100000 order by dept; +select dept +from employee +where sum(salary) > 100000 +order by dept; ``` ### D ```sql -select dept from employee group by dept where sum(salary) > 100000; +select dept +from employee +group by dept +where sum(salary) > 100000; ``` diff --git "a/data/2.MySQL\344\270\255\351\230\266/5.\345\255\220\346\237\245\350\257\242/1.\347\233\270\345\205\263\345\255\220\346\237\245\350\257\242/subquery.md" "b/data/2.MySQL\344\270\255\351\230\266/5.\345\255\220\346\237\245\350\257\242/1.\347\233\270\345\205\263\345\255\220\346\237\245\350\257\242/subquery.md" index 0a1568fc4442f8feb563f0571417ac4fe06f776e..160d7f13880b848583edf237e1da7a2cedfa5d2b 100644 --- "a/data/2.MySQL\344\270\255\351\230\266/5.\345\255\220\346\237\245\350\257\242/1.\347\233\270\345\205\263\345\255\220\346\237\245\350\257\242/subquery.md" +++ "b/data/2.MySQL\344\270\255\351\230\266/5.\345\255\220\346\237\245\350\257\242/1.\347\233\270\345\205\263\345\255\220\346\237\245\350\257\242/subquery.md" @@ -48,7 +48,8 @@ having salary > max(salary) ```sql select l.id, l.name, l.dept, l.salary from employee as l - join employee as r on l.salary > max(r.salary) + join employee as r + on l.salary > max(r.salary) where r.dept = 'sale' group by r.dept ``` @@ -58,7 +59,9 @@ group by r.dept ```sql select id, name, dept, salary from employee -having salary > (select max(salary) from employee where dept = 'sale') +having salary > (select max(salary) + from employee + where dept = 'sale') ``` diff --git "a/data/2.MySQL\344\270\255\351\230\266/5.\345\255\220\346\237\245\350\257\242/2. ANY/any.md" "b/data/2.MySQL\344\270\255\351\230\266/5.\345\255\220\346\237\245\350\257\242/2. ANY/any.md" index 7179d35012989c8459f90fc8d162ba4b051f675d..841e6d994a0c29f7b01fa10153d82624fc9ae149 100644 --- "a/data/2.MySQL\344\270\255\351\230\266/5.\345\255\220\346\237\245\350\257\242/2. ANY/any.md" +++ "b/data/2.MySQL\344\270\255\351\230\266/5.\345\255\220\346\237\245\350\257\242/2. ANY/any.md" @@ -25,7 +25,9 @@ create table employee( ```sql select id, name, dept, salary from employee as o -where o.salary < any(select salary from employee as i where i.dept=o.dept) +where o.salary < any(select salary + from employee as i + where i.dept=o.dept) ``` ## 选项 @@ -35,7 +37,8 @@ where o.salary < any(select salary from employee as i where i.dept=o.dept) ```sql select id, name, dept, salary from employee as o -join employee as i on o.dept = i.dept and o.salary < i.salary +join employee as i on + o.dept = i.dept and o.salary < i.salary ``` ### B @@ -43,7 +46,8 @@ join employee as i on o.dept = i.dept and o.salary < i.salary ```sql 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 +left join employee as i on + o.dept = i.dept and o.salary < i.salary where i.id is null; ``` @@ -52,6 +56,7 @@ where i.id is null; ```sql 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 + 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/5.\345\255\220\346\237\245\350\257\242/3.ALL/all.md" "b/data/2.MySQL\344\270\255\351\230\266/5.\345\255\220\346\237\245\350\257\242/3.ALL/all.md" index fb7614b9e217a0ca038b92cf2bfd4356ecfe427d..f0f97ab637ca60915d50b4f978553a6830c352d3 100644 --- "a/data/2.MySQL\344\270\255\351\230\266/5.\345\255\220\346\237\245\350\257\242/3.ALL/all.md" +++ "b/data/2.MySQL\344\270\255\351\230\266/5.\345\255\220\346\237\245\350\257\242/3.ALL/all.md" @@ -25,7 +25,10 @@ create table employee( ```sql select id, name, dept from employee as o -where 'assistant' != all(select post from employee as i where o.dept = i.dept); +where 'assistant' != + all(select post + from employee as i + where o.dept = i.dept); ``` ## 选项 @@ -35,7 +38,10 @@ where 'assistant' != all(select post from employee as i where o.dept = i.dept); ```sql select id, name, dept from employee as o -where 'assistant' = all(select post from employee as i where o.dept = i.dept); +where 'assistant' = + all(select post + from employee as i + where o.dept = i.dept); ``` ### B @@ -43,14 +49,19 @@ where 'assistant' = all(select post from employee as i where o.dept = i.dept); ```sql select id, name, dept from employee as o -where 'assistant' != all(select post from employee as i where o.dept = i.dept); +where 'assistant' != + all(select post + from employee as i + where o.dept = i.dept); ``` ### C ```sql select id, name, dept from employee as o -where 'assistant' != all(select post from employee as i); +where 'assistant' != + all(select post + from employee as i); ``` ### D @@ -58,5 +69,8 @@ where 'assistant' != all(select post from employee as i); ```sql select id, name, dept from employee as o -where 'assistant' != ANY(select post from employee as i where o.dept = i.dept); +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/5.\345\255\220\346\237\245\350\257\242/4.EXISTS/exists.md" "b/data/2.MySQL\344\270\255\351\230\266/5.\345\255\220\346\237\245\350\257\242/4.EXISTS/exists.md" index 095e382017a95daa0b1d7280dc615b5d7a3e3b89..9753b51b9426f572d60216385b6aebb6884c52ec 100644 --- "a/data/2.MySQL\344\270\255\351\230\266/5.\345\255\220\346\237\245\350\257\242/4.EXISTS/exists.md" +++ "b/data/2.MySQL\344\270\255\351\230\266/5.\345\255\220\346\237\245\350\257\242/4.EXISTS/exists.md" @@ -26,7 +26,10 @@ create table employee( ```sql select id, name, dept from employee as o -where not exists(select * from employee as i where o.dept = i.dept and post='assistant'); +where not exists( + select * + from employee as i + where o.dept = i.dept and post='assistant'); ``` ## 选项 @@ -36,14 +39,19 @@ where not exists(select * from employee as i where o.dept = i.dept and post='ass ```sql select id, name, dept from employee as o -where exists(select * from employee as i where o.dept = i.dept and post='assistant'); +where exists( + select * + from employee as i + where o.dept = i.dept and post='assistant'); ``` ### B ```sql select id, name, dept from employee as o -where 'assistant' != exists(select post from employee as i); +where 'assistant' != exists( + select post + from employee as i); ``` ### C @@ -51,5 +59,8 @@ where 'assistant' != exists(select post from employee as i); ```sql select id, name, dept from employee as o -where 'assistant' = not exists(select post from employee as i where o.dept = i.dept); +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/5.\345\255\220\346\237\245\350\257\242/5. IN/in.md" "b/data/2.MySQL\344\270\255\351\230\266/5.\345\255\220\346\237\245\350\257\242/5. IN/in.md" index fe43dccabf83711fae50b0ea1a660fed9302b56c..ac05ae169b76c0fa0837d554344aadbb55b53997 100644 --- "a/data/2.MySQL\344\270\255\351\230\266/5.\345\255\220\346\237\245\350\257\242/5. IN/in.md" +++ "b/data/2.MySQL\344\270\255\351\230\266/5.\345\255\220\346\237\245\350\257\242/5. IN/in.md" @@ -43,7 +43,9 @@ where dept in (select 'dev', 'hr'); ```sql select id, dept, name, post from employee -where dept in (select * from 'dev', 'hr'); +where dept in + (select * + from 'dev', 'hr'); ``` ### C diff --git "a/data/2.MySQL\344\270\255\351\230\266/5.\345\255\220\346\237\245\350\257\242/6. \345\210\227\345\255\220\346\237\245\350\257\242/in_column.md" "b/data/2.MySQL\344\270\255\351\230\266/5.\345\255\220\346\237\245\350\257\242/6. \345\210\227\345\255\220\346\237\245\350\257\242/in_column.md" index 07e4b531e913b147e4f5ffe12f6274e3d126afab..6afe590531977349c39fe70759bbe2137fd3d444 100644 --- "a/data/2.MySQL\344\270\255\351\230\266/5.\345\255\220\346\237\245\350\257\242/6. \345\210\227\345\255\220\346\237\245\350\257\242/in_column.md" +++ "b/data/2.MySQL\344\270\255\351\230\266/5.\345\255\220\346\237\245\350\257\242/6. \345\210\227\345\255\220\346\237\245\350\257\242/in_column.md" @@ -24,10 +24,10 @@ create table employee ## 答案 ```sql -select distinct(dept) as dept, - (select count(*) - from employee as i - where i.dept = o.dept) as emp +select distinct(dept) as dept, + (select count(*) + from employee as i + where i.dept = o.dept) as emp from employee as o; ``` @@ -36,28 +36,28 @@ from employee as o; ### A ```sql -select distinct(dept) as dept, - (select count(*) - from employee as i) as emp +select distinct(dept) as dept, + (select count(*) + from employee as i) as emp from employee as o; ``` ### B ```sql -select distinct(dept) as dept, - (select count(*) - from employee - where dept = dept) as emp +select distinct(dept) as dept, + (select count(*) + from employee + where dept = dept) as emp from employee ``` ### C ```sql -select dept as dept, - (select count(*) - from employee as i - where i.dept = o.dept) as emp +select dept as dept, + (select count(*) + from employee as i + where i.dept = o.dept) as emp from employee as o ``` \ No newline at end of file diff --git "a/data/2.MySQL\344\270\255\351\230\266/6.\350\277\236\346\216\245\346\237\245\350\257\242/2. LEFT JOIN/left_join.md" "b/data/2.MySQL\344\270\255\351\230\266/6.\350\277\236\346\216\245\346\237\245\350\257\242/2. LEFT JOIN/left_join.md" index 2398f054967921290be639bc853fcd3110b7fce5..88649510412e120402eafac6bbb2fa8847bbd4e1 100644 --- "a/data/2.MySQL\344\270\255\351\230\266/6.\350\277\236\346\216\245\346\237\245\350\257\242/2. LEFT JOIN/left_join.md" +++ "b/data/2.MySQL\344\270\255\351\230\266/6.\350\277\236\346\216\245\346\237\245\350\257\242/2. LEFT JOIN/left_join.md" @@ -34,8 +34,11 @@ Joe 想要列出所有的部门,如果这个部门有部门助理(post 为 ` ```sql select d.id, d.name, e.name as assistant from department as d - left join employee as e on e.dept = d.id -where e.post = 'assistant' + left join (select name, dept_id + from employee + where post='assistant') as e on e.dept_id = d.id + + ``` ## 选项 diff --git "a/data/2.MySQL\344\270\255\351\230\266/6.\350\277\236\346\216\245\346\237\245\350\257\242/3. RIGHT JOIN/right_join.md" "b/data/2.MySQL\344\270\255\351\230\266/6.\350\277\236\346\216\245\346\237\245\350\257\242/3. RIGHT JOIN/right_join.md" index 37305199b7295c501cbf7cc1cd472eee84f33128..43ca05f929770646fafe7b60a495f3ed70646c80 100644 --- "a/data/2.MySQL\344\270\255\351\230\266/6.\350\277\236\346\216\245\346\237\245\350\257\242/3. RIGHT JOIN/right_join.md" +++ "b/data/2.MySQL\344\270\255\351\230\266/6.\350\277\236\346\216\245\346\237\245\350\257\242/3. RIGHT JOIN/right_join.md" @@ -46,7 +46,7 @@ where d.id is null; ```sql select e.id, e.name, e.dept from employee as e - right join department as d on d.id = e.dept + right join department as d on d.id = e.dept where e.id is null; ``` @@ -55,7 +55,7 @@ where e.id is null; ```sql select e.id, e.name, e.dept from employee as e - right join department as d on d.id = e.dept + right join department as d on d.id = e.dept where d.id is null; ``` diff --git "a/data/2.MySQL\344\270\255\351\230\266/7. \347\264\242\345\274\225/2.\345\210\233\345\273\272\347\264\242\345\274\225/config.json" "b/data/2.MySQL\344\270\255\351\230\266/7. \347\264\242\345\274\225/2.\345\210\233\345\273\272\347\264\242\345\274\225/config.json" index 2094d1ab96a2100d83dbca773f59f56814329865..9f8abae295288cdf59b4ac45b9655d3cce2f3ddd 100644 --- "a/data/2.MySQL\344\270\255\351\230\266/7. \347\264\242\345\274\225/2.\345\210\233\345\273\272\347\264\242\345\274\225/config.json" +++ "b/data/2.MySQL\344\270\255\351\230\266/7. \347\264\242\345\274\225/2.\345\210\233\345\273\272\347\264\242\345\274\225/config.json" @@ -1,6 +1,9 @@ { "node_id": "mysql-fe65d5c615ad40f8ac056cc654f2d788", - "keywords": ["create index", "创建索引"], + "keywords": [ + "create index", + "创建索引" + ], "children": [], "export": [ "create_index.json" diff --git "a/data/2.MySQL\344\270\255\351\230\266/7. \347\264\242\345\274\225/2.\345\210\233\345\273\272\347\264\242\345\274\225/create_index.md" "b/data/2.MySQL\344\270\255\351\230\266/7. \347\264\242\345\274\225/2.\345\210\233\345\273\272\347\264\242\345\274\225/create_index.md" index 082df2f1d9c48f1add4028d25f4f5a366e104859..ec6897552453b0074e493de313fc0067ebc35758 100644 --- "a/data/2.MySQL\344\270\255\351\230\266/7. \347\264\242\345\274\225/2.\345\210\233\345\273\272\347\264\242\345\274\225/create_index.md" +++ "b/data/2.MySQL\344\270\255\351\230\266/7. \347\264\242\345\274\225/2.\345\210\233\345\273\272\347\264\242\345\274\225/create_index.md" @@ -27,7 +27,8 @@ create table goods( ## 答案 ```sql -create index idx_goods_category on goods(category_id); +create index idx_goods_category + on goods(category_id); ``` ## 选项 @@ -35,17 +36,20 @@ create index idx_goods_category on goods(category_id); ### A ```sql -create unique index idx_goods_category on goods(category_id); +create unique index idx_goods_category + on goods(category_id); ``` ### B ```sql -create index idx_goods_category on goods(name); +create index idx_goods_category + on goods(name); ``` ### C ```sql -alter table goods add unique index (category_id); +alter table goods + add unique index (category_id); ``` \ No newline at end of file diff --git "a/data/2.MySQL\344\270\255\351\230\266/7. \347\264\242\345\274\225/3.\345\210\240\351\231\244\347\264\242\345\274\225/drop_index.md" "b/data/2.MySQL\344\270\255\351\230\266/7. \347\264\242\345\274\225/3.\345\210\240\351\231\244\347\264\242\345\274\225/drop_index.md" index 920b3449577bf7af2ee3379ed7758bdcf521b7d0..962e97115b88fa49fdd7e75fd088b9eb685d234a 100644 --- "a/data/2.MySQL\344\270\255\351\230\266/7. \347\264\242\345\274\225/3.\345\210\240\351\231\244\347\264\242\345\274\225/drop_index.md" +++ "b/data/2.MySQL\344\270\255\351\230\266/7. \347\264\242\345\274\225/3.\345\210\240\351\231\244\347\264\242\345\274\225/drop_index.md" @@ -20,7 +20,8 @@ show index from goods; 查看 goods 表的索引(假设查到是 idx_goods_category),然后执行 ```sql -alter table goods drop index idx_goods_category; +alter table goods + drop index idx_goods_category; ``` ## 选项 @@ -36,7 +37,8 @@ show index from goods; 查看 goods 表的索引(假设查到是 idx_goods_category),然后执行 ```sql -alter table goods delete index idx_goods_category; +alter table goods + delete index idx_goods_category; ``` ### B @@ -50,7 +52,8 @@ show index from goods; 查看 goods 表的索引(假设查到是 idx_goods_category),然后执行 ```sql -alter table goods remove index idx_goods_category; +alter table goods + remove index idx_goods_category; ``` ### C @@ -64,7 +67,8 @@ show index from goods; 查看 goods 表的索引(假设查到是 idx_goods_category),然后执行 ```sql -alter table goods drop idx_goods_category; +alter table goods + drop idx_goods_category; ``` diff --git "a/data/3.MySQL\351\253\230\351\230\266/1.\346\267\261\345\205\245\347\264\242\345\274\225/1.\345\224\257\344\270\200\347\264\242\345\274\225/unique.md" "b/data/3.MySQL\351\253\230\351\230\266/1.\346\267\261\345\205\245\347\264\242\345\274\225/1.\345\224\257\344\270\200\347\264\242\345\274\225/unique.md" index f0316a958649b162a03bec0a55fc3b98107278b9..3b6b0dbc39f481631852e1c05a8cd82e1a970fb3 100644 --- "a/data/3.MySQL\351\253\230\351\230\266/1.\346\267\261\345\205\245\347\264\242\345\274\225/1.\345\224\257\344\270\200\347\264\242\345\274\225/unique.md" +++ "b/data/3.MySQL\351\253\230\351\230\266/1.\346\267\261\345\205\245\347\264\242\345\274\225/1.\345\224\257\344\270\200\347\264\242\345\274\225/unique.md" @@ -25,7 +25,8 @@ Joe 需要确保同一个类型下没有重名的商品,他应该怎么做? ## 答案 ```sql -alter table goods add unique index (category_id, name); +alter table goods + add unique index (category_id, name); ``` ## 选项 @@ -33,17 +34,20 @@ alter table goods add unique index (category_id, name); ### A ```sql -alter table goods add index (category_id, name); +alter table goods + add index (category_id, name); ``` ### B ```sql -alter table goods add unique index (category_id + name); +alter table goods + add unique index (category_id + name); ``` ### C ```sql -alter table goods add unique index (concat(category_id, name)); +alter table goods + add unique index (concat(category_id, name)); ``` diff --git "a/data/3.MySQL\351\253\230\351\230\266/1.\346\267\261\345\205\245\347\264\242\345\274\225/2.\345\205\250\345\200\274\345\214\271\351\205\215/config.json" "b/data/3.MySQL\351\253\230\351\230\266/1.\346\267\261\345\205\245\347\264\242\345\274\225/2.\345\205\250\345\200\274\345\214\271\351\205\215/config.json" index 90ad368262934e2d68b811e80ef0ca25e414526b..d1d673481f42b498c4c7ada060f51113a91a7c25 100644 --- "a/data/3.MySQL\351\253\230\351\230\266/1.\346\267\261\345\205\245\347\264\242\345\274\225/2.\345\205\250\345\200\274\345\214\271\351\205\215/config.json" +++ "b/data/3.MySQL\351\253\230\351\230\266/1.\346\267\261\345\205\245\347\264\242\345\274\225/2.\345\205\250\345\200\274\345\214\271\351\205\215/config.json" @@ -7,7 +7,12 @@ "export": [ "total_index.json" ], - "keywords_must": [["mysql", "全值匹配"]], + "keywords_must": [ + [ + "mysql", + "全值匹配" + ] + ], "keywords_forbid": [], "group": 2 } \ No newline at end of file diff --git "a/data/3.MySQL\351\253\230\351\230\266/1.\346\267\261\345\205\245\347\264\242\345\274\225/2.\345\205\250\345\200\274\345\214\271\351\205\215/total_index.md" "b/data/3.MySQL\351\253\230\351\230\266/1.\346\267\261\345\205\245\347\264\242\345\274\225/2.\345\205\250\345\200\274\345\214\271\351\205\215/total_index.md" index b98932fbc8e393307baa49d1de0ac8175fcfe99c..623f6ed8f1b27568f7e875b9557d921e20e366d7 100644 --- "a/data/3.MySQL\351\253\230\351\230\266/1.\346\267\261\345\205\245\347\264\242\345\274\225/2.\345\205\250\345\200\274\345\214\271\351\205\215/total_index.md" +++ "b/data/3.MySQL\351\253\230\351\230\266/1.\346\267\261\345\205\245\347\264\242\345\274\225/2.\345\205\250\345\200\274\345\214\271\351\205\215/total_index.md" @@ -25,7 +25,8 @@ create table goods( ## 答案 ```sql -alter table goods add index (name, price); +alter table goods + add index (name, price); ``` ## 选项 @@ -39,11 +40,14 @@ alter table goods add index (name, price); 建立一个计算字段: ```sql -alter table goods add summary varchar(1024) generated always as (concat(name, '(', 0.5, ')')); +alter table goods + add summary varchar(1024) + generated always as (concat(name, '(', 0.5, ')')); ``` ### C ```sql -alter table goods add index (concat(name, price)); +alter table goods + add index (concat(name, price)); ``` \ No newline at end of file diff --git "a/data/3.MySQL\351\253\230\351\230\266/1.\346\267\261\345\205\245\347\264\242\345\274\225/3.\345\214\271\351\205\215\351\241\272\345\272\217/match_fields.md" "b/data/3.MySQL\351\253\230\351\230\266/1.\346\267\261\345\205\245\347\264\242\345\274\225/3.\345\214\271\351\205\215\351\241\272\345\272\217/match_fields.md" index 2607b91f20331c44f9e702050be04752a7f6ae1a..6c391144cc5a318d0208bcef5950015ef27b8b5b 100644 --- "a/data/3.MySQL\351\253\230\351\230\266/1.\346\267\261\345\205\245\347\264\242\345\274\225/3.\345\214\271\351\205\215\351\241\272\345\272\217/match_fields.md" +++ "b/data/3.MySQL\351\253\230\351\230\266/1.\346\267\261\345\205\245\347\264\242\345\274\225/3.\345\214\271\351\205\215\351\241\272\345\272\217/match_fields.md" @@ -29,7 +29,12 @@ Joe 发现有大量查询 `select id, category_id, name, price from goods where 将该查询改写为 ```sql -select id, category_id, name, price from goods where category_id=? and name=?; +select id, + category_id, + name, + price +from goods +where category_id=? and name=?; ``` ## 选项 @@ -39,7 +44,12 @@ select id, category_id, name, price from goods where category_id=? and name=?; 将该查询改写为 ```sql -select id, category_id, name, price from goods where category_id and name= (?, ?); +select id, + category_id, + name, + price +from goods +where category_id and name= (?, ?); ``` ### B @@ -47,7 +57,12 @@ select id, category_id, name, price from goods where category_id and name= (?, ? 将该查询改写为 ```sql -select id, category_id, name, price from goods where not (category_id !=? or name != ?); +select id, + category_id, + name, + price +from goods +where not (category_id !=? or name != ?); ``` ### C @@ -55,6 +70,11 @@ select id, category_id, name, price from goods where not (category_id !=? or nam 将该查询改写为 ```sql -select id, category_id, name, price from goods where not (category_id !=?) and not (name != ?); +select id, + category_id, + name, + price +from goods +where not (category_id !=?) and not (name != ?); ``` diff --git "a/data/3.MySQL\351\253\230\351\230\266/1.\346\267\261\345\205\245\347\264\242\345\274\225/4.\347\273\204\345\220\210\347\264\242\345\274\225/combinate.md" "b/data/3.MySQL\351\253\230\351\230\266/1.\346\267\261\345\205\245\347\264\242\345\274\225/4.\347\273\204\345\220\210\347\264\242\345\274\225/combinate.md" index 7b2d5d816af480b39ff4a0cdc2b5132f17350826..b753404cbebf3b363a662f7cef14f304d5173db7 100644 --- "a/data/3.MySQL\351\253\230\351\230\266/1.\346\267\261\345\205\245\347\264\242\345\274\225/4.\347\273\204\345\220\210\347\264\242\345\274\225/combinate.md" +++ "b/data/3.MySQL\351\253\230\351\230\266/1.\346\267\261\345\205\245\347\264\242\345\274\225/4.\347\273\204\345\220\210\347\264\242\345\274\225/combinate.md" @@ -14,7 +14,19 @@ create table goods( ) ``` -现有大量查询 `select id, category_id, name, price, stock from goods where stock=? and category_id=? and name like ?`, +现有大量查询 +```sql +select + id, + category_id, + name, + price, + stock +from goods +where stock=? + and category_id=? + and name like ?`, +``` Joe 应该如何优化?