From ff78e9ab06833e612d94051226924ac64251a3c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E5=BF=97=E6=99=A8?= Date: Mon, 27 Jun 2022 11:12:16 +0800 Subject: [PATCH] fix bug --- .../2.\347\231\273\345\275\225/prepare.md" | 10 +++---- .../create_database.md" | 14 +++++----- .../auto_increment.md" | 10 +++---- .../create_table.md" | 12 ++++----- .../drop_table.md" | 12 ++++----- .../engine.md" | 10 +++---- .../numbers.md" | 4 +-- .../datetime.md" | 12 ++++----- .../description.md" | 12 ++++----- .../binary.md" | 12 ++++----- .../1.\346\217\222\345\205\245/insert.md" | 12 ++++----- .../2.\344\277\256\346\224\271/update.md" | 10 +++---- .../3.\345\210\240\351\231\244/delete.md" | 14 +++++----- .../1.SELECT/select.md" | 12 ++++----- .../2.WHERE/where.md" | 12 ++++----- .../geo.md" | 12 ++++----- .../1.\350\241\250/create_table.md" | 8 +++--- .../2.\350\247\206\345\233\276/view.md" | 12 ++++----- .../create_function.md" | 8 +++--- .../create_procedure.md" | 10 +++---- .../drop_function.md" | 8 +++--- .../unique.md" | 2 +- .../unique_2.md" | 2 +- .../audit.md" | 14 +++++----- .../trigger.md" | 2 +- .../upgrade_engine.md" | 6 ++--- .../create_user.md" | 8 +++--- .../grant.md" | 12 ++++----- .../role.md" | 8 +++--- .../view_privileges.md" | 8 +++--- .../revoke.md" | 8 +++--- .../change_password.md" | 8 +++--- .../drop_user.md" | 8 +++--- .../limit_action.md" | 10 +++---- .../2. BETWEEN/between.md" | 10 +++---- .../3.CASE/case.md" | 12 ++++----- .../4.DISTINCT/distinct.md" | 12 ++++----- .../5.ORDER BY/order_by.md" | 14 +++++----- .../6.UNION/union.md" | 14 +++++----- .../regex.md" | 8 +++--- .../paged.md" | 10 +++---- .../cast.md" | 4 +-- .../convert.md" | 12 ++++----- .../1. \350\256\241\346\225\260/count.md" | 2 +- .../2. \346\261\202\345\222\214/sum.md" | 12 ++++----- .../min.md" | 12 ++++----- .../max.md" | 12 ++++----- .../avg.md" | 12 ++++----- .../6.HAVING/having.md" | 12 ++++----- .../subquery.md" | 10 +++---- .../2. ANY/any.md" | 10 +++---- .../3.ALL/all.md" | 12 ++++----- .../4.EXISTS/exists.md" | 12 ++++----- .../5. IN/in.md" | 12 ++++----- .../in_column.md" | 10 +++---- .../1.INNER JOIN/join_self.md" | 12 ++++----- .../2. LEFT JOIN/left_join.md" | 14 +++++----- .../3. RIGHT JOIN/right_join.md" | 14 +++++----- .../4. CROSS JOIN/cross_join.md" | 16 ++++++------ .../salary.md" | 12 ++++----- .../create_index.md" | 10 +++---- .../drop_index.md" | 16 ++++++------ .../unique.md" | 10 +++---- .../total_index.md" | 8 +++--- .../match_fields.md" | 10 +++---- .../combinate.md" | 10 +++---- .../geo_index.md" | 12 ++++----- .../full_text_index.md" | 10 +++---- .../invisible.md" | 12 ++++----- .../daily_payment.md" | 14 +++++----- .../continuous.md" | 10 +++---- .../to_root.md" | 10 +++---- .../2.Window Function/salary.md" | 14 +++++----- .../pivot.md" | 10 +++---- .../4.Double Not Exists/DoubleNotExists.md" | 12 ++++----- .../score.md" | 12 ++++----- .../transaction.md" | 4 +-- .../1.IF/if.md" | 10 +++---- .../2.LOOP/loop.md" | 10 +++---- .../3.REPEAT/repeat.md" | 12 ++++----- .../4.WHILE/while.md" | 12 ++++----- .../5. \346\270\270\346\240\207/cursor.md" | 14 +++++----- .../generated.md" | 10 +++---- .../customer_order.md" | 2 +- .../daily_payment2.md" | 20 +++++++------- .../filter.md" | 26 +++++++++---------- .../1. SHOW STATUS/show_status.md" | 8 +++--- .../3. EXPLAIN/explain.md" | 8 +++--- 88 files changed, 465 insertions(+), 465 deletions(-) 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 9116223..ad32a0e 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" @@ -24,7 +24,7 @@ sudo su mysql mysql ``` 创建数据库用户 joe 并授权: -```mysql +```sql create user 'joe'@'localhost' identified by 'joe'; grant all privileges on *.* to `joe`@`localhost`; flush privileges ; @@ -40,7 +40,7 @@ flush privileges ; mysql mysql ``` 为 joe 授权 -```mysql +```sql grant all privileges on *.* to joe; flush privileges ; ``` @@ -54,7 +54,7 @@ mysql mysql ``` 为 joe 授权 -```mysql +```sql grant all privileges on *.* to joe; flush privileges ; ``` @@ -67,7 +67,7 @@ mysql mysql ``` 创建数据库用户 joe -```mysql +```sql create user 'joe'@'localhost' identified by 'joe'; flush privileges ; ``` @@ -80,7 +80,7 @@ sudo su mysql mysql ``` 创建数据库用户 joe 并授权: -```mysql +```sql 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/3.\344\275\277\347\224\250\346\225\260\346\215\256\345\272\223/1. \345\210\233\345\273\272\345\222\214\345\210\240\351\231\244\346\225\260\346\215\256\345\272\223/create_database.md" "b/data/1.MySQL\345\210\235\351\230\266/3.\344\275\277\347\224\250\346\225\260\346\215\256\345\272\223/1. \345\210\233\345\273\272\345\222\214\345\210\240\351\231\244\346\225\260\346\215\256\345\272\223/create_database.md" index 65a249c..cd467b8 100644 --- "a/data/1.MySQL\345\210\235\351\230\266/3.\344\275\277\347\224\250\346\225\260\346\215\256\345\272\223/1. \345\210\233\345\273\272\345\222\214\345\210\240\351\231\244\346\225\260\346\215\256\345\272\223/create_database.md" +++ "b/data/1.MySQL\345\210\235\351\230\266/3.\344\275\277\347\224\250\346\225\260\346\215\256\345\272\223/1. \345\210\233\345\273\272\345\222\214\345\210\240\351\231\244\346\225\260\346\215\256\345\272\223/create_database.md" @@ -11,7 +11,7 @@ Joe 在开发机上创建了一个名为 goods 的数据库,做了一些练习 ## 答案 -```mysql +```sql drop database goods; create database goods; ``` @@ -20,14 +20,14 @@ create database goods; ### A -```mysql +```sql delete database goods; create database goods; ``` ### B -```mysql +```sql if exists(database goods) then begin drop database goods; @@ -37,7 +37,7 @@ create database goods; ### C -```mysql +```sql use goods; drop database goods; create database goods; @@ -45,7 +45,7 @@ create database goods; ### D -```mysql +```sql use goods; drop database goods; make database goods; @@ -53,14 +53,14 @@ make database goods; ### E -```mysql +```sql drop database goods; make database goods; ``` ### F -```mysql +```sql cd goods; drop database goods; create database goods; diff --git "a/data/1.MySQL\345\210\235\351\230\266/3.\344\275\277\347\224\250\346\225\260\346\215\256\345\272\223/2.\345\210\233\345\273\272\345\222\214\345\210\240\351\231\244\350\241\250/auto_increment.md" "b/data/1.MySQL\345\210\235\351\230\266/3.\344\275\277\347\224\250\346\225\260\346\215\256\345\272\223/2.\345\210\233\345\273\272\345\222\214\345\210\240\351\231\244\350\241\250/auto_increment.md" index 6019961..5cbdc4c 100644 --- "a/data/1.MySQL\345\210\235\351\230\266/3.\344\275\277\347\224\250\346\225\260\346\215\256\345\272\223/2.\345\210\233\345\273\272\345\222\214\345\210\240\351\231\244\350\241\250/auto_increment.md" +++ "b/data/1.MySQL\345\210\235\351\230\266/3.\344\275\277\347\224\250\346\225\260\346\215\256\345\272\223/2.\345\210\233\345\273\272\345\222\214\345\210\240\351\231\244\350\241\250/auto_increment.md" @@ -11,7 +11,7 @@ Joe 需要重建一个 id 为自增字段的 goods_category 。他已经删除 ## 答案 -```mysql +```sql CREATE TABLE goods_category ( id INT PRIMARY KEY AUTO_INCREMENT, @@ -24,7 +24,7 @@ CREATE TABLE goods_category ### A -```mysql +```sql CREATE TABLE goods_category ( id INT PRIMARY KEY SERIALS, @@ -35,7 +35,7 @@ CREATE TABLE goods_category ### B -```mysql +```sql CREATE TABLE goods_category ( id INT , @@ -48,7 +48,7 @@ CREATE TABLE goods_category ### C -```mysql +```sql CREATE TABLE goods_category ( id INT PRIMARY KEY, @@ -59,7 +59,7 @@ CREATE TABLE goods_category ### D -```mysql +```sql CREATE TABLE goods_category ( id INT PRIMARY KEY SERIALS, diff --git "a/data/1.MySQL\345\210\235\351\230\266/3.\344\275\277\347\224\250\346\225\260\346\215\256\345\272\223/2.\345\210\233\345\273\272\345\222\214\345\210\240\351\231\244\350\241\250/create_table.md" "b/data/1.MySQL\345\210\235\351\230\266/3.\344\275\277\347\224\250\346\225\260\346\215\256\345\272\223/2.\345\210\233\345\273\272\345\222\214\345\210\240\351\231\244\350\241\250/create_table.md" index be70f68..569b6ae 100644 --- "a/data/1.MySQL\345\210\235\351\230\266/3.\344\275\277\347\224\250\346\225\260\346\215\256\345\272\223/2.\345\210\233\345\273\272\345\222\214\345\210\240\351\231\244\350\241\250/create_table.md" +++ "b/data/1.MySQL\345\210\235\351\230\266/3.\344\275\277\347\224\250\346\225\260\346\215\256\345\272\223/2.\345\210\233\345\273\272\345\222\214\345\210\240\351\231\244\350\241\250/create_table.md" @@ -11,7 +11,7 @@ Joe 想要在 goods 数据库创建一个 goods_category 表,管理商品的 ## 答案 -```mysql +```sql CREATE TABLE goods_category ( id INT PRIMARY KEY , @@ -24,7 +24,7 @@ CREATE TABLE goods_category ### A -```mysql +```sql MAKE TABLE goods_category ( id INT PRIMARY KEY , @@ -35,7 +35,7 @@ MAKE TABLE goods_category ### B -```mysql +```sql DROP TABLE goods_category ( id INT PRIMARY KEY, @@ -46,7 +46,7 @@ DROP TABLE goods_category ### C -```mysql +```sql SAVE TABLE goods_category ( id INT PRIMARY KEY, @@ -57,7 +57,7 @@ SAVE TABLE goods_category ### D -```mysql +```sql ADD TABLE goods_category ( id INT PRIMARY KEY, @@ -68,7 +68,7 @@ ADD TABLE goods_category ### E -```mysql +```sql PUT TABLE goods_category ( id INT PRIMARY KEY, diff --git "a/data/1.MySQL\345\210\235\351\230\266/3.\344\275\277\347\224\250\346\225\260\346\215\256\345\272\223/2.\345\210\233\345\273\272\345\222\214\345\210\240\351\231\244\350\241\250/drop_table.md" "b/data/1.MySQL\345\210\235\351\230\266/3.\344\275\277\347\224\250\346\225\260\346\215\256\345\272\223/2.\345\210\233\345\273\272\345\222\214\345\210\240\351\231\244\350\241\250/drop_table.md" index 355a419..71dbc19 100644 --- "a/data/1.MySQL\345\210\235\351\230\266/3.\344\275\277\347\224\250\346\225\260\346\215\256\345\272\223/2.\345\210\233\345\273\272\345\222\214\345\210\240\351\231\244\350\241\250/drop_table.md" +++ "b/data/1.MySQL\345\210\235\351\230\266/3.\344\275\277\347\224\250\346\225\260\346\215\256\345\272\223/2.\345\210\233\345\273\272\345\222\214\345\210\240\351\231\244\350\241\250/drop_table.md" @@ -11,7 +11,7 @@ Joe 想要删除数据库中的 good_category 表,他应该怎么操作? ## 答案 -```mysql +```sql drop table goods_category; ``` @@ -19,30 +19,30 @@ drop table goods_category; ### A -```mysql +```sql delete table good_category; ``` ### B -```mysql +```sql delete table where name = 'good_category'; ``` ### C -```mysql +```sql remove table good_category; ``` ### D -```mysql +```sql truncate table goods_category; ``` ### E -```mysql +```sql clean table goods_category; ``` diff --git "a/data/1.MySQL\345\210\235\351\230\266/3.\344\275\277\347\224\250\346\225\260\346\215\256\345\272\223/4.\345\255\230\345\202\250\345\274\225\346\223\216/engine.md" "b/data/1.MySQL\345\210\235\351\230\266/3.\344\275\277\347\224\250\346\225\260\346\215\256\345\272\223/4.\345\255\230\345\202\250\345\274\225\346\223\216/engine.md" index 3b48699..1f789b7 100644 --- "a/data/1.MySQL\345\210\235\351\230\266/3.\344\275\277\347\224\250\346\225\260\346\215\256\345\272\223/4.\345\255\230\345\202\250\345\274\225\346\223\216/engine.md" +++ "b/data/1.MySQL\345\210\235\351\230\266/3.\344\275\277\347\224\250\346\225\260\346\215\256\345\272\223/4.\345\255\230\345\202\250\345\274\225\346\223\216/engine.md" @@ -11,7 +11,7 @@ Joe 需要确保 goods_category 表的存储引擎为 innodb ,那么建表语 ## 答案 -```mysql +```sql CREATE TABLE goods_category ( id INT, @@ -24,7 +24,7 @@ CREATE TABLE goods_category ### A -```mysql +```sql CREATE TABLE goods_category ( id INT, @@ -35,7 +35,7 @@ CREATE TABLE goods_category ### B -```mysql +```sql WITH ENGINE=INNODB CREATE TABLE goods_category ( id INT, @@ -46,7 +46,7 @@ WITH ENGINE=INNODB CREATE TABLE goods_category ### C -```mysql +```sql SAVE TABLE goods_category ( id INT, @@ -57,7 +57,7 @@ SAVE TABLE goods_category ### D -```mysql +```sql CREATE TABLE goods_category ( id INT, diff --git "a/data/1.MySQL\345\210\235\351\230\266/4.\346\225\260\346\215\256\347\261\273\345\236\213/1.\346\225\260\345\200\274\347\261\273\345\236\213/numbers.md" "b/data/1.MySQL\345\210\235\351\230\266/4.\346\225\260\346\215\256\347\261\273\345\236\213/1.\346\225\260\345\200\274\347\261\273\345\236\213/numbers.md" index 9546a9c..95581d4 100644 --- "a/data/1.MySQL\345\210\235\351\230\266/4.\346\225\260\346\215\256\347\261\273\345\236\213/1.\346\225\260\345\200\274\347\261\273\345\236\213/numbers.md" +++ "b/data/1.MySQL\345\210\235\351\230\266/4.\346\225\260\346\215\256\347\261\273\345\236\213/1.\346\225\260\345\200\274\347\261\273\345\236\213/numbers.md" @@ -9,7 +9,7 @@ Joe 需要使用下列表做一项数值计算 * `show databases;` 列出所有数据库 * `show tables;` 列出所有表 -```mysql +```sql create table points( id int primary key auto_increment, x int, @@ -19,7 +19,7 @@ create table points( 计算查询为: -```mysql +```sql select id, (x^2 + y^2)/2 as result from points; ``` diff --git "a/data/1.MySQL\345\210\235\351\230\266/4.\346\225\260\346\215\256\347\261\273\345\236\213/2.\346\227\245\346\234\237\345\222\214\346\227\266\351\227\264\347\261\273\345\236\213/datetime.md" "b/data/1.MySQL\345\210\235\351\230\266/4.\346\225\260\346\215\256\347\261\273\345\236\213/2.\346\227\245\346\234\237\345\222\214\346\227\266\351\227\264\347\261\273\345\236\213/datetime.md" index e93781d..0b0b99b 100644 --- "a/data/1.MySQL\345\210\235\351\230\266/4.\346\225\260\346\215\256\347\261\273\345\236\213/2.\346\227\245\346\234\237\345\222\214\346\227\266\351\227\264\347\261\273\345\236\213/datetime.md" +++ "b/data/1.MySQL\345\210\235\351\230\266/4.\346\225\260\346\215\256\347\261\273\345\236\213/2.\346\227\245\346\234\237\345\222\214\346\227\266\351\227\264\347\261\273\345\236\213/datetime.md" @@ -2,7 +2,7 @@ Joe 写了一个订单表的创建语句: -```mysql +```sql create table orders ( id int primary key auto_increment, item_id int, @@ -23,7 +23,7 @@ create table orders ( ## 答案 -```mysql +```sql create table orders ( id int primary key auto_increment, item_id int, @@ -38,7 +38,7 @@ create table orders ( ### A -```mysql +```sql create table orders ( id int primary key auto_increment, item_id int, @@ -51,7 +51,7 @@ create table orders ( ### B -```mysql +```sql create table orders ( id int primary key auto_increment, item_id int, @@ -64,7 +64,7 @@ create table orders ( ### C -```mysql +```sql create table orders ( id int primary key auto_increment, item_id int, @@ -77,7 +77,7 @@ create table orders ( ### D -```mysql +```sql create table orders ( id int primary key auto_increment, item_id int, diff --git "a/data/1.MySQL\345\210\235\351\230\266/4.\346\225\260\346\215\256\347\261\273\345\236\213/3.\346\226\207\346\234\254\345\255\227\347\254\246\344\270\262\347\261\273\345\236\213/description.md" "b/data/1.MySQL\345\210\235\351\230\266/4.\346\225\260\346\215\256\347\261\273\345\236\213/3.\346\226\207\346\234\254\345\255\227\347\254\246\344\270\262\347\261\273\345\236\213/description.md" index a41eaff..9ccc095 100644 --- "a/data/1.MySQL\345\210\235\351\230\266/4.\346\225\260\346\215\256\347\261\273\345\236\213/3.\346\226\207\346\234\254\345\255\227\347\254\246\344\270\262\347\261\273\345\236\213/description.md" +++ "b/data/1.MySQL\345\210\235\351\230\266/4.\346\225\260\346\215\256\347\261\273\345\236\213/3.\346\226\207\346\234\254\345\255\227\347\254\246\344\270\262\347\261\273\345\236\213/description.md" @@ -2,7 +2,7 @@ Joe 在设计订单表,他已经完成了下列内容: -```mysql +```sql create table orders ( id int primary key auto_increment, item_id int, @@ -24,7 +24,7 @@ create table orders ( ## 答案 -```mysql +```sql create table orders ( id int primary key auto_increment, item_id int, @@ -40,7 +40,7 @@ create table orders ( ### A -```mysql +```sql create table orders ( id int primary key auto_increment, item_id int, @@ -54,7 +54,7 @@ create table orders ( ### B -```mysql +```sql create table orders ( id int primary key auto_increment, item_id int, @@ -68,7 +68,7 @@ create table orders ( ### C -```mysql +```sql create table orders ( id int primary key auto_increment, item_id int, @@ -82,7 +82,7 @@ create table orders ( ### D -```mysql +```sql create table orders ( id int primary key auto_increment, item_id int, diff --git "a/data/1.MySQL\345\210\235\351\230\266/4.\346\225\260\346\215\256\347\261\273\345\236\213/4.\344\272\214\350\277\233\345\210\266\345\255\227\347\254\246\344\270\262\347\261\273\345\236\213/binary.md" "b/data/1.MySQL\345\210\235\351\230\266/4.\346\225\260\346\215\256\347\261\273\345\236\213/4.\344\272\214\350\277\233\345\210\266\345\255\227\347\254\246\344\270\262\347\261\273\345\236\213/binary.md" index d703b8a..1d521a4 100644 --- "a/data/1.MySQL\345\210\235\351\230\266/4.\346\225\260\346\215\256\347\261\273\345\236\213/4.\344\272\214\350\277\233\345\210\266\345\255\227\347\254\246\344\270\262\347\261\273\345\236\213/binary.md" +++ "b/data/1.MySQL\345\210\235\351\230\266/4.\346\225\260\346\215\256\347\261\273\345\236\213/4.\344\272\214\350\277\233\345\210\266\345\255\227\347\254\246\344\270\262\347\261\273\345\236\213/binary.md" @@ -2,7 +2,7 @@ 现在 Joe 的订单表已经有了如下形态: -```mysql +```sql create table orders ( id int primary key auto_increment, item_id int, @@ -25,7 +25,7 @@ create table orders ( ## 答案 -```mysql +```sql create table orders ( id int primary key auto_increment, item_id int, @@ -42,7 +42,7 @@ create table orders ( ### A -```mysql +```sql create table orders ( id int primary key auto_increment, item_id int, @@ -57,7 +57,7 @@ create table orders ( ### B -```mysql +```sql create table orders ( id int primary key auto_increment, item_id int, @@ -72,7 +72,7 @@ create table orders ( ### C -```mysql +```sql create table orders ( id int primary key auto_increment, item_id int, @@ -87,7 +87,7 @@ create table orders ( ### D -```mysql +```sql create table orders ( id int primary key auto_increment, item_id int, 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 3465818..56258b1 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" @@ -2,7 +2,7 @@ Goods 数据库中有一个表: -```mysql +```sql create table book( id int primary key auto_increment, title varchar(200) not null , @@ -25,7 +25,7 @@ create unique index idx_book_isbn on book(isbn); ## 答案 -```mysql +```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'; ``` @@ -34,28 +34,28 @@ insert into book(title, price, isbn, publish_at) select 'a other book title', 25 ### 唯一键冲突 -```mysql +```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'; ``` ### 缺少必要的列 -```mysql +```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'; ``` ### 类型错误 -```mysql +```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'; ``` ### 违反非空约束 -```mysql +```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'; ``` 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 abcf196..a1d7327 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" @@ -2,7 +2,7 @@ 现有 employee 表如下: -```mysql +```sql create table employee ( id serial primary key, @@ -23,7 +23,7 @@ Joe 希望修改销售部(dept 字段为 sale)员工 Dora Muk 的工资,将其 ## 答案 -```mysql +```sql update employee set salary = salary + 1000 where dept = 'sale' and name = 'Dora Muk'; ``` @@ -31,20 +31,20 @@ update employee set salary = salary + 1000 where dept = 'sale' and name = 'Dora ### 过滤条件不严谨 -```mysql +```sql update employee set salary = salary + 1000 where name = 'Dora Muk'; ``` ### 缺少过滤条件 -```mysql +```sql update employee set salary = salary + 1000; ``` ### 错误的赋值语句 -```mysql +```sql 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 7397bbc..7571ad4 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" @@ -2,7 +2,7 @@ 现在 orders 表结构如下: -```mysql +```sql create table orders ( id int primary key auto_increment, item_id int, @@ -28,7 +28,7 @@ create table orders ( 在一个独立的定时任务中执行 -```mysql +```sql delete from orders where deal; @@ -40,7 +40,7 @@ where deal; 在一个独立的定时任务中执行 -```mysql +```sql truncate orders; ``` @@ -48,7 +48,7 @@ truncate orders; 在一个独立的定时任务中执行 -```mysql +```sql delete from orders; ``` @@ -57,7 +57,7 @@ from orders; 在一个独立的定时任务中执行 -```mysql +```sql drop table orders; create table if not exists orders ( id int primary key auto_increment, @@ -75,7 +75,7 @@ create table if not exists orders ( 建立视图 -```mysql +```sql create view order_view as select id, meta, content, created_at from orders @@ -88,7 +88,7 @@ where not deal; 在一个独立的定时任务中执行 -```mysql +```sql delete from orders where deal; 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 042dd90..cb25e6d 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" @@ -11,7 +11,7 @@ ## 答案 -```mysql +```sql from test select abc; ``` @@ -20,31 +20,31 @@ from test select abc; ### A -```mysql +```sql select 3.14; ``` ### B -```mysql +```sql select * from employee; ``` ### C -```mysql +```sql select * from employee where dept = 'hr'; ``` ### D -```mysql +```sql select id, name, dept, salary from employee where salary > 10000; ``` ### E -```mysql +```sql select now(); ``` 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 0e755a9..4b282d6 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" @@ -2,7 +2,7 @@ Joe 希望从 orders 表 -```mysql +```sql create table orders ( id int primary key auto_increment, @@ -27,7 +27,7 @@ create table orders ## 答案 -```mysql +```sql select id from orders where date(ts) = '2022-05-25' @@ -38,7 +38,7 @@ where date(ts) = '2022-05-25' ### A -```mysql +```sql select id from (select * from orders where date(ts) = '2022-05-25') as o where unit_prise < 20; @@ -46,7 +46,7 @@ where unit_prise < 20; ### B -```mysql +```sql select id from orders where date(ts) = '2022-05-25' @@ -55,7 +55,7 @@ where date(ts) = '2022-05-25' ### C -```mysql +```sql select id from orders if date(ts) = '2022-05-25' or unit_prise < 20; @@ -63,7 +63,7 @@ if date(ts) = '2022-05-25' or unit_prise < 20; ### D -```mysql +```sql select id from orders which date(ts) = '2022-05-25' 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 6345f34..1bc5e96 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" @@ -2,7 +2,7 @@ Points 表结构如下: -```mysql +```sql create table points( id int primary key auto_increment, x float, @@ -21,7 +21,7 @@ create table points( ## 答案 -```mysql +```sql select id, sqrt(x^2 + y^2) from points; ``` @@ -29,24 +29,24 @@ select id, sqrt(x^2 + y^2) from points; ### A -```mysql +```sql select sqrt(vx+vy) from (select x^2 as vx, y^2 as vy from points) as t; ``` ### B -```mysql +```sql select sqrt(vx + vy) from points where x^2 as vx, y^2 as vy ; ``` ### C -```mysql +```sql select id + sqrt(x^2 + y^2) from points; ``` ### D -```mysql +```sql 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/1.\350\241\250/create_table.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/1.\350\241\250/create_table.md" index a7cae2d..e67a6f4 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/1.\350\241\250/create_table.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/1.\350\241\250/create_table.md" @@ -12,7 +12,7 @@ ## 答案 -```mysql +```sql create table trade ( id int primary key auto_increment, content varchar(8000), @@ -24,7 +24,7 @@ create table trade ( ### 主键没有设置自增,不符合题意 -```mysql +```sql create table trade ( id integer primary key, content varchar(8000), @@ -34,7 +34,7 @@ create table trade ( ### 时间戳没有设置默认值 -```mysql +```sql create table trade ( id serial primary key, content varchar(8000), @@ -44,7 +44,7 @@ create table trade ( ### 没有主键,不符合题设 -```mysql +```sql create table trade ( id serial, content varchar(8000), 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/2.\350\247\206\345\233\276/view.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/2.\350\247\206\345\233\276/view.md" index 12e91aa..3c9bc80 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/2.\350\247\206\345\233\276/view.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/2.\350\247\206\345\233\276/view.md" @@ -2,7 +2,7 @@ Joe 需要给 goods 表 -```mysql +```sql create table goods( id int primary key auto_increment, category_id int, @@ -25,7 +25,7 @@ create table goods( ## 答案 -```mysql +```sql CREATE VIEW view_name_price AS SELECT name, price @@ -37,7 +37,7 @@ CREATE VIEW view_name_price ### A -```mysql +```sql CREATE VIEW view_name_price AS SELECT name, price @@ -46,7 +46,7 @@ CREATE VIEW view_name_price ### B -```mysql +```sql CREATE VIEW view_name_price AS SELECT * @@ -56,7 +56,7 @@ CREATE VIEW view_name_price ### C -```mysql +```sql CREATE VIEW view_name_price AS BEGIN @@ -68,7 +68,7 @@ END; ### D -```mysql +```sql CREATE VIEW view_name_price AS BEGIN 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_function.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_function.md" index 16b01a8..dc50d73 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_function.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_function.md" @@ -12,7 +12,7 @@ ## 答案 -```mysql +```sql create function individual_income_tax(salary decimal(12, 4)) returns decimal(12, 4) deterministic begin @@ -24,7 +24,7 @@ end; ### A -```mysql +```sql create store function individual_income_tax(salary decimal(12, 4)) returns decimal(12, 4) deterministic begin @@ -34,7 +34,7 @@ end; ### B -```mysql +```sql create function individual_income_tax(salary decimal(12, 4)) deterministic begin @@ -45,7 +45,7 @@ end; ### C -```mysql +```sql create function decimal(12, 4) individual_income_tax(salary decimal(12, 4)) begin -- ... 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 ed1c286..2f663f7 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" @@ -13,7 +13,7 @@ Joe 希望这个计算更紧凑一些,在已经有 individual_income_tax 的 ## 答案 -```mysql +```sql 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); @@ -25,7 +25,7 @@ end; ### A -```mysql +```sql 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); @@ -36,7 +36,7 @@ end; ### B -```mysql +```sql create procedure sp_idt(salary decimal(12, 4)) returns (decimal(12, 4), decimal(12, 4)) begin declare tax, take_home decimal(12, 4); @@ -48,7 +48,7 @@ end; ### C -```mysql +```sql create procedure sp_idt(in salary decimal(12, 4), out tax decimal(12, 4), out take_home decimal(12, 4)) returns void begin set tax = individual_income_tax(salary); @@ -58,7 +58,7 @@ end; ### D -```mysql +```sql create procedure sp_idt(in salary decimal(12, 4)) begin declare tax, take_home decimal(12, 4); 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/drop_function.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/drop_function.md" index 86d19fd..bf71304 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/drop_function.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/drop_function.md" @@ -11,7 +11,7 @@ Joe 将计税逻辑放到了 sp_idt 中,现在不需要 individual_income_tax ## 答案 -```mysql +```sql drop function individual_income_tax; ``` @@ -19,20 +19,20 @@ drop function individual_income_tax; ### A -```mysql +```sql delete function individual_income_tax; ``` ### B -```mysql +```sql remove function individual_income_tax; ``` ### C -```mysql +```sql drop function individual_income_tax(decimal(12, 4)); ``` 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/4.\347\264\242\345\274\225\345\222\214\347\272\246\346\235\237/unique.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/4.\347\264\242\345\274\225\345\222\214\347\272\246\346\235\237/unique.md" index 0bcaf5a..1f642c2 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/4.\347\264\242\345\274\225\345\222\214\347\272\246\346\235\237/unique.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/4.\347\264\242\345\274\225\345\222\214\347\272\246\346\235\237/unique.md" @@ -2,7 +2,7 @@ 现有一个图书登记表: -```mysql +```sql create table book( id int primary key auto_increment, title text, 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/4.\347\264\242\345\274\225\345\222\214\347\272\246\346\235\237/unique_2.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/4.\347\264\242\345\274\225\345\222\214\347\272\246\346\235\237/unique_2.md" index f1062a0..5130309 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/4.\347\264\242\345\274\225\345\222\214\347\272\246\346\235\237/unique_2.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/4.\347\264\242\345\274\225\345\222\214\347\272\246\346\235\237/unique_2.md" @@ -2,7 +2,7 @@ 现有一个图书登记表: -```mysql +```sql create table book( id int primary key auto_increment, title text, 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 3d5c538..befab47 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" @@ -2,7 +2,7 @@ Orders 表 -```mysql +```sql create table orders ( id int primary key auto_increment, @@ -17,7 +17,7 @@ create table orders 记录了未完成的订单。审计部门现在需要记录其变更——新增或删除,该表不会发生update——即将修改都记录到 orders_log 表 -```mysql +```sql create table orders_log ( log_id int primary key auto_increment, @@ -44,7 +44,7 @@ create table orders_log ## 答案 -```mysql +```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'); @@ -58,7 +58,7 @@ create trigger out_orders after delete on orders ### A -```mysql +```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'); @@ -67,7 +67,7 @@ create trigger in_orders after insert on orders ### B -```mysql +```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) @@ -77,7 +77,7 @@ create trigger out_orders after delete on orders ### C -```mysql +```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'); @@ -88,7 +88,7 @@ create trigger in_orders after insert on orders ### D -```mysql +```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'); 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/trigger.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/trigger.md" index b276fe9..928eda2 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/trigger.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/trigger.md" @@ -2,7 +2,7 @@ SmartMarket 公司的OA数据库中包含以下结构: -```mysql +```sql create table employee( id serial primary key , name varchar(256), 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/6.\345\255\230\345\202\250\345\274\225\346\223\216/upgrade_engine.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/6.\345\255\230\345\202\250\345\274\225\346\223\216/upgrade_engine.md" index 6db7c63..5735d93 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/6.\345\255\230\345\202\250\345\274\225\346\223\216/upgrade_engine.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/6.\345\255\230\345\202\250\345\274\225\346\223\216/upgrade_engine.md" @@ -11,7 +11,7 @@ Goods 表的存储引擎是 MyISAM,Joe 需要把它修改为 InnoDB,他应 ## 答案 -```mysql +```sql alter table goods engine innodb; ``` @@ -19,7 +19,7 @@ alter table goods engine innodb; ### A -```mysql +```sql alter table goods set engine innodb; ``` @@ -31,7 +31,7 @@ alter table goods set engine innodb; ### C -```mysql +```sql alter table goods add engine innodb; ``` diff --git "a/data/2.MySQL\344\270\255\351\230\266/10.\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/10.\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 5ced97e..009aa91 100644 --- "a/data/2.MySQL\344\270\255\351\230\266/10.\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/10.\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" @@ -12,7 +12,7 @@ Joe 要给数据组的 John 创建一个用户,他希望John 能够从 `192.16 ## 答案 -```mysql +```sql create user 'john'@'192.168.7.42' identified by 'goods123' password expire; grant select on goods.* to 'john'@'192.168.7.42'; flush privileges; @@ -22,7 +22,7 @@ flush privileges; ### A -```mysql +```sql create user 'john'@'192.168.7.42' identified by 'goods123'; grant select on goods.* to 'john'@'192.168.7.42'; flush privileges; @@ -30,7 +30,7 @@ flush privileges; ### B -```mysql +```sql create user 'john'@'192.168.7.42' identified by 'goods123'; grant usage on goods.* to 'john'@'192.168.7.42'; flush privileges; @@ -38,7 +38,7 @@ flush privileges; ### C -```mysql +```sql 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/10.\347\224\250\346\210\267\345\222\214\346\235\203\351\231\220/2.\344\270\272\347\224\250\346\210\267\346\216\210\346\235\203/grant.md" "b/data/2.MySQL\344\270\255\351\230\266/10.\347\224\250\346\210\267\345\222\214\346\235\203\351\231\220/2.\344\270\272\347\224\250\346\210\267\346\216\210\346\235\203/grant.md" index 406fbb9..6f84c53 100644 --- "a/data/2.MySQL\344\270\255\351\230\266/10.\347\224\250\346\210\267\345\222\214\346\235\203\351\231\220/2.\344\270\272\347\224\250\346\210\267\346\216\210\346\235\203/grant.md" +++ "b/data/2.MySQL\344\270\255\351\230\266/10.\347\224\250\346\210\267\345\222\214\346\235\203\351\231\220/2.\344\270\272\347\224\250\346\210\267\346\216\210\346\235\203/grant.md" @@ -11,7 +11,7 @@ ## 答案 -```mysql +```sql grant select on table employee to joe; ``` @@ -19,30 +19,30 @@ grant select on table employee to joe; ### 权限名错误 -```mysql +```sql grant query on table employee to joe; ``` ### 权限名错误 -```mysql +```sql grant read on table employee to joe; ``` ### 操作关键词错误 -```mysql +```sql grant select on table employee of joe; ``` ### 操作错误 -```mysql +```sql grant select on table employee.* of joe; ``` ### 权限过高 -```mysql +```sql grant all on table employee to joe; ``` diff --git "a/data/2.MySQL\344\270\255\351\230\266/10.\347\224\250\346\210\267\345\222\214\346\235\203\351\231\220/2.\344\270\272\347\224\250\346\210\267\346\216\210\346\235\203/role.md" "b/data/2.MySQL\344\270\255\351\230\266/10.\347\224\250\346\210\267\345\222\214\346\235\203\351\231\220/2.\344\270\272\347\224\250\346\210\267\346\216\210\346\235\203/role.md" index ece0c3c..4d55e89 100644 --- "a/data/2.MySQL\344\270\255\351\230\266/10.\347\224\250\346\210\267\345\222\214\346\235\203\351\231\220/2.\344\270\272\347\224\250\346\210\267\346\216\210\346\235\203/role.md" +++ "b/data/2.MySQL\344\270\255\351\230\266/10.\347\224\250\346\210\267\345\222\214\346\235\203\351\231\220/2.\344\270\272\347\224\250\346\210\267\346\216\210\346\235\203/role.md" @@ -12,7 +12,7 @@ Joe 现在是团队的 DBA,公司数据分析组有 Fred、Alice、James、Jon ## 答案 -```mysql +```sql create role analysis; grant analysis to fred, alice, james, jone; grant select on goods.* to analysis; @@ -23,13 +23,13 @@ flush privileges; ### 将来人员变动管理会很繁琐 -```mysql +```sql grant select on goods.* to fred, alice, james, jone; ``` ### 错误的语法 -```mysql +```sql create role analysis; grant analysis to fred, alice, james, jone; grant all on all tables in schema goods to analysis; @@ -38,7 +38,7 @@ flush privileges; ### 过度授权 -```mysql +```sql create role analysis; grant analysis to fred, alice, james, jone; grant select on *.* to analysis; diff --git "a/data/2.MySQL\344\270\255\351\230\266/10.\347\224\250\346\210\267\345\222\214\346\235\203\351\231\220/3.\346\237\245\347\234\213\347\224\250\346\210\267\346\235\203\351\231\220/view_privileges.md" "b/data/2.MySQL\344\270\255\351\230\266/10.\347\224\250\346\210\267\345\222\214\346\235\203\351\231\220/3.\346\237\245\347\234\213\347\224\250\346\210\267\346\235\203\351\231\220/view_privileges.md" index fd338fa..0eb3025 100644 --- "a/data/2.MySQL\344\270\255\351\230\266/10.\347\224\250\346\210\267\345\222\214\346\235\203\351\231\220/3.\346\237\245\347\234\213\347\224\250\346\210\267\346\235\203\351\231\220/view_privileges.md" +++ "b/data/2.MySQL\344\270\255\351\230\266/10.\347\224\250\346\210\267\345\222\214\346\235\203\351\231\220/3.\346\237\245\347\234\213\347\224\250\346\210\267\346\235\203\351\231\220/view_privileges.md" @@ -11,7 +11,7 @@ Joe 想要查看 Fred 的 MySQL 账户 `'fred'@'%'` 的权限,他应该怎么 ## 答案 -```mysql +```sql show grants for fred; ``` @@ -19,18 +19,18 @@ show grants for fred; ### A -```mysql +```sql select grants from fred; ``` ### B -```mysql +```sql show privileges for fred; ``` ### B -```mysql +```sql show privileges from fred; ``` diff --git "a/data/2.MySQL\344\270\255\351\230\266/10.\347\224\250\346\210\267\345\222\214\346\235\203\351\231\220/4.\346\222\244\351\224\200\347\224\250\346\210\267\346\235\203\351\231\220/revoke.md" "b/data/2.MySQL\344\270\255\351\230\266/10.\347\224\250\346\210\267\345\222\214\346\235\203\351\231\220/4.\346\222\244\351\224\200\347\224\250\346\210\267\346\235\203\351\231\220/revoke.md" index 4495725..ac3e7fc 100644 --- "a/data/2.MySQL\344\270\255\351\230\266/10.\347\224\250\346\210\267\345\222\214\346\235\203\351\231\220/4.\346\222\244\351\224\200\347\224\250\346\210\267\346\235\203\351\231\220/revoke.md" +++ "b/data/2.MySQL\344\270\255\351\230\266/10.\347\224\250\346\210\267\345\222\214\346\235\203\351\231\220/4.\346\222\244\351\224\200\347\224\250\346\210\267\346\235\203\351\231\220/revoke.md" @@ -12,7 +12,7 @@ ## 答案 -```mysql +```sql revoke select on trade from fred; ``` @@ -20,19 +20,19 @@ revoke select on trade from fred; ### 操作错误 -```mysql +```sql grant not select on trade to fred; ``` ### 操作关键字错误 -```mysql +```sql revoke select on trade to fred; ``` ### 指定权限错误 -```mysql +```sql revoke owned trade from fred; ``` diff --git "a/data/2.MySQL\344\270\255\351\230\266/10.\347\224\250\346\210\267\345\222\214\346\235\203\351\231\220/5.\344\277\256\346\224\271\347\224\250\346\210\267\345\257\206\347\240\201/change_password.md" "b/data/2.MySQL\344\270\255\351\230\266/10.\347\224\250\346\210\267\345\222\214\346\235\203\351\231\220/5.\344\277\256\346\224\271\347\224\250\346\210\267\345\257\206\347\240\201/change_password.md" index e22d8f8..d8576a7 100644 --- "a/data/2.MySQL\344\270\255\351\230\266/10.\347\224\250\346\210\267\345\222\214\346\235\203\351\231\220/5.\344\277\256\346\224\271\347\224\250\346\210\267\345\257\206\347\240\201/change_password.md" +++ "b/data/2.MySQL\344\270\255\351\230\266/10.\347\224\250\346\210\267\345\222\214\346\235\203\351\231\220/5.\344\277\256\346\224\271\347\224\250\346\210\267\345\257\206\347\240\201/change_password.md" @@ -13,7 +13,7 @@ Joe 准备将这个账户的口令初始化为 `goods123fred` , ## 答案 -```mysql +```sql alter user 'fred'@'%' identified by 'goods123fred' password expire; ``` @@ -21,18 +21,18 @@ alter user 'fred'@'%' identified by 'goods123fred' password expire; ### A -```mysql +```sql alter user 'fred'@'%' identified by 'goods123fred'; ``` ### B -```mysql +```sql alter user 'fred'@'%' set password 'goods123fred'; ``` ### C -```mysql +```sql alter user 'fred'@'%' set password 'goods123fred' expire; ``` \ No newline at end of file diff --git "a/data/2.MySQL\344\270\255\351\230\266/10.\347\224\250\346\210\267\345\222\214\346\235\203\351\231\220/6.\345\210\240\351\231\244\347\224\250\346\210\267/drop_user.md" "b/data/2.MySQL\344\270\255\351\230\266/10.\347\224\250\346\210\267\345\222\214\346\235\203\351\231\220/6.\345\210\240\351\231\244\347\224\250\346\210\267/drop_user.md" index f392dbe..1f8623a 100644 --- "a/data/2.MySQL\344\270\255\351\230\266/10.\347\224\250\346\210\267\345\222\214\346\235\203\351\231\220/6.\345\210\240\351\231\244\347\224\250\346\210\267/drop_user.md" +++ "b/data/2.MySQL\344\270\255\351\230\266/10.\347\224\250\346\210\267\345\222\214\346\235\203\351\231\220/6.\345\210\240\351\231\244\347\224\250\346\210\267/drop_user.md" @@ -11,7 +11,7 @@ Jane 从公司离职,Joe 需要从数据库服务器删除她的账号 `'jane' ## 答案 -```mysql +```sql drop user 'jane'@'%'; ``` @@ -19,18 +19,18 @@ drop user 'jane'@'%'; ### A -```mysql +```sql delete user 'jane'@'%'; ``` ### B -```mysql +```sql remove user 'jane'@'%'; ``` ### C -```mysql +```sql revoke user 'jane'@'%'; ``` \ No newline at end of file diff --git "a/data/2.MySQL\344\270\255\351\230\266/10.\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/10.\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 567bdcf..be5a7a9 100644 --- "a/data/2.MySQL\344\270\255\351\230\266/10.\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/10.\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" @@ -11,7 +11,7 @@ Joe 需要限制数据分析组(role analysis)的用户, 每小时查询次 ## 答案 -```mysql +```sql alter user analysis with MAX_QUERIES_PER_HOUR 10000; ``` @@ -19,25 +19,25 @@ alter user analysis with MAX_QUERIES_PER_HOUR 10000; ### A -```mysql +```sql set user analysis with MAX_QUERIES_PER_HOUR 10000; ``` ### B -```mysql +```sql alter role analysis with MAX_QUERIES_PER_HOUR 10000; ``` ### C -```mysql +```sql alter role analysis with MAX_QUERIES_PER_HOUR=10000; ``` ### D -```mysql +```sql 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 502a4e6..4a42b6f 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" @@ -1,7 +1,7 @@ # Between Joe 要查询 goods 表 -```mysql +```sql create table goods( id int primary key auto_increment, category_id int, @@ -23,7 +23,7 @@ create table goods( ## 答案 -```mysql +```sql SELECT * FROM goods HAVING price BETWEEN 1000 AND 2000; ``` @@ -32,19 +32,19 @@ SELECT * FROM goods HAVING price BETWEEN 1000 AND 2000; ### A -```mysql +```sql SELECT * FROM goods WHERE price BETWEEN 1000 AND 2000; ``` ### B -```mysql +```sql SELECT * FROM goods WHERE price >= 1000 AND price <= 2000; ``` ### C -```mysql +```sql 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/3.CASE/case.md" "b/data/2.MySQL\344\270\255\351\230\266/2.\346\237\245\350\257\242\350\277\233\351\230\266/3.CASE/case.md" index c1fb23c..306c44a 100644 --- "a/data/2.MySQL\344\270\255\351\230\266/2.\346\237\245\350\257\242\350\277\233\351\230\266/3.CASE/case.md" +++ "b/data/2.MySQL\344\270\255\351\230\266/2.\346\237\245\350\257\242\350\277\233\351\230\266/3.CASE/case.md" @@ -2,7 +2,7 @@ Goods 表结构如下 -```mysql +```sql create table goods( id int primary key auto_increment, category_id int, @@ -26,7 +26,7 @@ normal,这个查询应该怎么写? ## 答案 -```mysql +```sql select name, case when price < 10 then 'cheap' @@ -40,7 +40,7 @@ from goods; ### A -```mysql +```sql select name, case price when < 10 then 'cheap' @@ -52,7 +52,7 @@ from goods; ### B -```mysql +```sql select name, case when price < 10 'cheap' @@ -64,7 +64,7 @@ from goods; ### C -```mysql +```sql select name, case when price < 10 then 'cheap' @@ -76,7 +76,7 @@ from goods; ### C -```mysql +```sql select name, case when price < 10 then 'cheap' 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 cfa34d6..52fba35 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" @@ -2,7 +2,7 @@ Joe 想统计以下 goods 表 -```mysql +```sql create table goods( id int primary key auto_increment, category_id int, @@ -25,7 +25,7 @@ create table goods( ## 答案 -```mysql +```sql select count(distinct price) from goods; ``` @@ -33,24 +33,24 @@ select count(distinct price) from goods; ### A -```mysql +```sql select count(distinct *) from goods; ``` ### B -```mysql +```sql select distinct count(price) from goods; ``` ### C -```mysql +```sql select count(price) from goods; ``` ### D -```mysql +```sql 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 e22463c..ae73cc9 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" @@ -2,7 +2,7 @@ Joe 需要根据员工表 -```mysql +```sql create table employee ( id serial primary key, @@ -23,7 +23,7 @@ create table employee ## 答案 -```mysql +```sql select id, name, dept, salary from employee order by dept, salary desc; ``` @@ -31,29 +31,29 @@ select id, name, dept, salary from employee order by dept, salary desc; ### A -```mysql +```sql select id, name, dept, salary from employee order by dept, salary; ``` ### B -```mysql +```sql select id, name, dept, salary from employee order by dept desc, salary desc; ``` ### C -```mysql +```sql select id, name, dept, salary from employee order by dept and salary desc; ``` ### D -```mysql +```sql select id, name, dept, salary from employee order by dept, salary, id, name; ``` ### E -```mysql +```sql 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/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 179ed07..641f9b8 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" @@ -2,7 +2,7 @@ 现有员工信息表和顾客信息表如下 -```mysql +```sql create table employee( id int primary key auto_increment, name varchar(256), @@ -32,7 +32,7 @@ Joe 需要员工和顾客的联系方式(姓名+地址)清单,用于邮寄 ## 答案 -```mysql +```sql select name, address from customer union @@ -44,7 +44,7 @@ from employee ### A -```mysql +```sql select * from customer union @@ -54,7 +54,7 @@ from employee ### B -```mysql +```sql select * from customer join employee @@ -62,7 +62,7 @@ join employee ### C -```mysql +```sql select * from customer join employee on customer.id = employee.id @@ -70,14 +70,14 @@ join employee on customer.id = employee.id ### D -```mysql +```sql select * from customer, employee ``` ### E -```mysql +```sql select name, address from customer, employee ``` 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/7.\346\255\243\345\210\231\350\241\250\350\276\276\345\274\217/regex.md" "b/data/2.MySQL\344\270\255\351\230\266/2.\346\237\245\350\257\242\350\277\233\351\230\266/7.\346\255\243\345\210\231\350\241\250\350\276\276\345\274\217/regex.md" index eab2c68..28a507e 100644 --- "a/data/2.MySQL\344\270\255\351\230\266/2.\346\237\245\350\257\242\350\277\233\351\230\266/7.\346\255\243\345\210\231\350\241\250\350\276\276\345\274\217/regex.md" +++ "b/data/2.MySQL\344\270\255\351\230\266/2.\346\237\245\350\257\242\350\277\233\351\230\266/7.\346\255\243\345\210\231\350\241\250\350\276\276\345\274\217/regex.md" @@ -11,7 +11,7 @@ Joe 想要找出 goods 表中所有名称包含牛奶的冰激凌,他应该怎 ## 答案 -```mysql +```sql select * from goods where name regexp '牛奶.*冰激凌'; @@ -21,7 +21,7 @@ where name regexp '牛奶.*冰激凌'; ### A -```mysql +```sql select * from goods where name like '牛奶%冰激凌' @@ -30,7 +30,7 @@ where name like '牛奶%冰激凌' ### B -```mysql +```sql select * from goods where name like '牛奶.*冰激凌'; @@ -38,7 +38,7 @@ where name like '牛奶.*冰激凌'; ### C -```mysql +```sql select * from goods where name regexp '牛奶冰激凌'; 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 7a44b43..01790f6 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" @@ -2,7 +2,7 @@ 我们有如下订单表: -```mysql +```sql create table orders ( id serial primary key, @@ -24,7 +24,7 @@ create table orders ## 答案 -```mysql +```sql select id, product_id, order_date, quantity, customer_id from orders where date = $1 @@ -35,7 +35,7 @@ offset $2 limit 100; ### 缺少 limit -```mysql +```sql select id, product_id, order_date, quantity, customer_id from orders where date = $1 @@ -44,7 +44,7 @@ offset $2; ### 缺少 offset -```mysql +```sql select id, product_id, order_date, quantity, customer_id from orders where date = $1; @@ -52,7 +52,7 @@ where date = $1; ### 结构不对 -```mysql +```sql select id, product_id, order_date, quantity, customer_id from orders where date = $1 and 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/cast.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/cast.md" index 21c9b2f..9591878 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/cast.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/cast.md" @@ -11,7 +11,7 @@ Joe 想要把字符串表示的整数转为整数类型,可行的方法是: ## 答案 -```mysql +```sql SELECT CAST('123' AS SIGNED); ``` @@ -19,7 +19,7 @@ SELECT CAST('123' AS SIGNED); ### A -```mysql +```sql select int('123'); ``` 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 6e681d7..61e4382 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" @@ -2,7 +2,7 @@ Joe 需要将下面这个查询 -```mysql +```sql select name from goods; ``` @@ -17,7 +17,7 @@ select name from goods; ## 答案 -```mysql +```sql select convert(name using 'gb18030') from goods; ``` @@ -26,27 +26,27 @@ select convert(name using 'gb18030') from goods; ### A -```mysql +```sql select str(name, 'gb18303') from goods; ``` ### B -```mysql +```sql select encode(decode(name, 'utf8mb4'), 'gb18303') from goods; ``` ### C -```mysql +```sql select convert(name from 'utf8mb4' to 'gb18303') from goods; ``` ### D -```mysql +```sql select convert(name to 'gb18303') from goods; ``` 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 25b2270..1042a31 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" @@ -16,7 +16,7 @@ mysql> select * from items; 当他执行 -```mysql +```sql 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 b9f84f8..641180d 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" @@ -2,7 +2,7 @@ Joe 想要得到 orders 表 -```mysql +```sql create table orders ( id int primary key auto_increment, item_id int, @@ -26,7 +26,7 @@ create table orders ( ## 答案 -```mysql +```sql select sum(total) from orders where deal and unit_price > 1000; ``` @@ -34,24 +34,24 @@ select sum(total) from orders where deal and unit_price > 1000; ### A -```mysql +```sql select sum(total) from orders where deal and unit_price > 1000; ``` ### B -```mysql +```sql select sum(total) from orders having deal and unit_price > 1000; ``` ### C -```mysql +```sql select sum(total) from orders group by deal having unit_price > 1000; ``` ### D -```mysql +```sql select sum(total) from orders having 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 8f1822d..bbf9ce4 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" @@ -2,7 +2,7 @@ Joe 想要得到 employee 表 -```mysql +```sql create table employee ( id serial primary key, @@ -23,7 +23,7 @@ create table employee ## 答案 -```mysql +```sql select dept, min(salary) from employee group by dept; ``` @@ -31,24 +31,24 @@ select dept, min(salary) from employee group by dept; ### A -```mysql +```sql select dept, min(salary) from employee; ``` ### B -```mysql +```sql select dept, min(salary) from employee; ``` ### C -```mysql +```sql select dept, min(salary) from employee; ``` ### D -```mysql +```sql 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/4. \346\234\200\345\244\247\345\200\274/max.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/4. \346\234\200\345\244\247\345\200\274/max.md" index a832059..5045850 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/4. \346\234\200\345\244\247\345\200\274/max.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/4. \346\234\200\345\244\247\345\200\274/max.md" @@ -2,7 +2,7 @@ 利用员工信息表: -```mysql +```sql create table employee ( id serial primary key, @@ -23,7 +23,7 @@ Joe 做了一些关于 max 函数的练习,其中不正确的是: ## 答案 -```mysql +```sql select id, dept, max(salary) as salary, name from employee group by dept @@ -35,7 +35,7 @@ group by dept ### A -```mysql +```sql select dept, max(salary) as salary from employee group by dept @@ -45,7 +45,7 @@ group by dept ### B -```mysql +```sql select max(salary) as salary from employee ``` @@ -54,7 +54,7 @@ from employee ### C -```mysql +```sql select dept, sum(salary) from employee group by dept @@ -65,7 +65,7 @@ having max(salary) < 20000 ### D -```mysql +```sql select dept, min(salary) from employee group by dept 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 63351b9..35dcd6b 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" @@ -2,7 +2,7 @@ Joe 想要得到 employee 表 -```mysql +```sql create table employee ( id serial primary key, @@ -23,7 +23,7 @@ create table employee ## 答案 -```mysql +```sql select dept, avg(salary) from employee group by dept; ``` @@ -31,24 +31,24 @@ select dept, avg(salary) from employee group by dept; ### A -```mysql +```sql select dept, avg(salary) from employee; ``` ### B -```mysql +```sql select dept, avg(salary) from employee; ``` ### C -```mysql +```sql select dept, avg(salary) from employee; ``` ### D -```mysql +```sql select dept, avg(salary) 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/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 de314fe..6f2958b 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" @@ -2,7 +2,7 @@ Joe 要从 employee 表 -```mysql +```sql create table employee ( id serial primary key, @@ -23,7 +23,7 @@ create table employee ## 答案 -```mysql +```sql select dept from employee group by dept having sum(salary) > 100000; ``` @@ -31,25 +31,25 @@ select dept from employee group by dept having sum(salary) > 100000; ### A -```mysql +```sql select dept from employee group by dept where sum(salary) > 100000; ``` ### B -```mysql +```sql select dept from employee where sum(salary) > 100000 group by dept; ``` ### C -```mysql +```sql select dept from employee where sum(salary) > 100000 order by dept; ``` ### D -```mysql +```sql 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 7c1636e..0a1568f 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" @@ -2,7 +2,7 @@ 现有员工表 -```mysql +```sql create table employee ( id serial primary key, @@ -23,7 +23,7 @@ Joe 希望找出比销售部(dept 为 sale)工资最高的员工工资更高 ## 答案 -```mysql +```sql select id, name, dept, salary from employee where salary > (select max(salary) @@ -35,7 +35,7 @@ where salary > (select max(salary) ### A -```mysql +```sql select id, name, dept, salary from employee where dept = 'sale' @@ -45,7 +45,7 @@ having salary > max(salary) ### B -```mysql +```sql select l.id, l.name, l.dept, l.salary from employee as l join employee as r on l.salary > max(r.salary) @@ -55,7 +55,7 @@ group by r.dept ### C -```mysql +```sql select id, name, dept, salary from employee 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 8bb0df8..7179d35 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" @@ -2,7 +2,7 @@ Joe 想要从员工表 -```mysql +```sql create table employee( id int primary key auto_increment, name varchar(256), @@ -22,7 +22,7 @@ create table employee( ## 答案 -```mysql +```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) @@ -32,7 +32,7 @@ where o.salary < any(select salary from employee as i where i.dept=o.dept) ### A -```mysql +```sql select id, name, dept, salary from employee as o join employee as i on o.dept = i.dept and o.salary < i.salary @@ -40,7 +40,7 @@ join employee as i on o.dept = i.dept and o.salary < i.salary ### B -```mysql +```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 @@ -49,7 +49,7 @@ where i.id is null; ### C -```mysql +```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 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 e37a6b7..fb7614b 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" @@ -2,7 +2,7 @@ Joe 想从员工表 -```mysql +```sql create table employee( id int primary key auto_increment, dept_id int, @@ -22,7 +22,7 @@ create table employee( ## 答案 -```mysql +```sql select id, name, dept from employee as o where 'assistant' != all(select post from employee as i where o.dept = i.dept); @@ -32,7 +32,7 @@ where 'assistant' != all(select post from employee as i where o.dept = i.dept); ### A -```mysql +```sql select id, name, dept from employee as o where 'assistant' = all(select post from employee as i where o.dept = i.dept); @@ -40,14 +40,14 @@ where 'assistant' = all(select post from employee as i where o.dept = i.dept); ### B -```mysql +```sql select id, name, dept from employee as o where 'assistant' != all(select post from employee as i where o.dept = i.dept); ``` ### C -```mysql +```sql select id, name, dept from employee as o where 'assistant' != all(select post from employee as i); @@ -55,7 +55,7 @@ where 'assistant' != all(select post from employee as i); ### D -```mysql +```sql select id, name, dept from employee as o where 'assistant' != ANY(select post from employee as i where o.dept = i.dept); 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 3101a28..bd7ae3e 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" @@ -2,7 +2,7 @@ Joe 想从员工表 -```mysql +```sql create table employee( id int primary key auto_increment, dept_id int, @@ -23,7 +23,7 @@ create table employee( ## 答案 -```mysql +```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'); @@ -33,7 +33,7 @@ where not exists(select * from employee as i where o.dept = i.dept and post='ass ### A -```mysql +```sql select id, name, dept from employee as o where exists(select * from employee as i where o.dept = i.dept and post='assistant'); @@ -41,14 +41,14 @@ where exists(select * from employee as i where o.dept = i.dept and post='assista ### B -```mysql +```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'); ``` ### C -```mysql +```sql select id, name, dept from employee as o where 'assistant' != exists(select post from employee as i); @@ -56,7 +56,7 @@ where 'assistant' != exists(select post from employee as i); ### D -```mysql +```sql select id, name, dept from employee as o where 'assistant' = not exists(select post from employee as i where o.dept = i.dept); 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 d561464..d1221eb 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" @@ -2,7 +2,7 @@ Joe 想要从员工表 -```mysql +```sql create table employee( id int primary key auto_increment, dept_id int, @@ -22,7 +22,7 @@ create table employee( ## 答案 -```mysql +```sql select id, dept, name, post from employee where dept in ('dev', 'hr'); @@ -32,7 +32,7 @@ where dept in ('dev', 'hr'); ### A -```mysql +```sql select id, dept, name, post from employee where dept in (select 'dev', 'hr'); @@ -40,7 +40,7 @@ where dept in (select 'dev', 'hr'); ### B -```mysql +```sql select id, dept, name, post from employee where dept in (select * from 'dev', 'hr'); @@ -48,7 +48,7 @@ where dept in (select * from 'dev', 'hr'); ### C -```mysql +```sql select id, dept, name, post from employee where dept in ('dev' and 'hr'); @@ -56,7 +56,7 @@ where dept in ('dev' and 'hr'); #### D -```mysql +```sql 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/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 d13c930..07e4b53 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" @@ -2,7 +2,7 @@ Joe 打算写一个查询,根据员工表 -```mysql +```sql create table employee ( id int primary key auto_increment, @@ -23,7 +23,7 @@ create table employee ## 答案 -```mysql +```sql select distinct(dept) as dept, (select count(*) from employee as i @@ -35,7 +35,7 @@ from employee as o; ### A -```mysql +```sql select distinct(dept) as dept, (select count(*) from employee as i) as emp @@ -44,7 +44,7 @@ from employee as o; ### B -```mysql +```sql select distinct(dept) as dept, (select count(*) from employee @@ -54,7 +54,7 @@ from employee ### C -```mysql +```sql select dept as dept, (select count(*) from employee as i 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/1.INNER JOIN/join_self.md" "b/data/2.MySQL\344\270\255\351\230\266/6.\350\277\236\346\216\245\346\237\245\350\257\242/1.INNER JOIN/join_self.md" index 929db35..f07beca 100644 --- "a/data/2.MySQL\344\270\255\351\230\266/6.\350\277\236\346\216\245\346\237\245\350\257\242/1.INNER JOIN/join_self.md" +++ "b/data/2.MySQL\344\270\255\351\230\266/6.\350\277\236\346\216\245\346\237\245\350\257\242/1.INNER JOIN/join_self.md" @@ -2,7 +2,7 @@ 现有 node 表如下: -```mysql +```sql create table node( id int primary key auto_increment, pid int, @@ -22,7 +22,7 @@ create table node( ## 答案 -```mysql +```sql select l.id as parent_id, l.content as parent_content, r.id as child_id, @@ -36,7 +36,7 @@ where l.content like 'fork-%'; ### A -```mysql +```sql select l.id as parent_id, l.content as parent_content, r.id as child_id, @@ -48,7 +48,7 @@ where l.content like 'fork-%'; ### B -```mysql +```sql select l.id as parent_id, l.content as parent_content, r.id as child_id, @@ -59,7 +59,7 @@ where l.id =(+) r.pid l.content like 'fork-%'; ### C -```mysql +```sql select l.id as parent_id, l.content as parent_content, r.id as child_id, @@ -71,7 +71,7 @@ where l.content like 'fork-%'; ### D -```mysql +```sql select l.id as parent_id, l.content as parent_content, r.id as child_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/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 3bc1547..37e919c 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" @@ -2,7 +2,7 @@ 现有部门表 -```mysql +```sql create table department( id int primary key auto_increment, name varchar(256) @@ -11,7 +11,7 @@ create table department( 和员工表 -```mysql +```sql create table employee( id int primary key auto_increment, dept_id int, @@ -31,7 +31,7 @@ Joe 想要列出所有的部门,如果这个部门有部门助理(post 为 ` ## 答案 -```mysql +```sql select d.id, d.name, e.name as assistant from department as d left join employee as e on e.dept = d.id @@ -42,7 +42,7 @@ where e.post = 'assistant' ### A -```mysql +```sql select d.id, d.name, e.name as assistant from department as d cross join employee as e on e.dept = d.id @@ -51,7 +51,7 @@ where e.post = 'assistant' ### B -```mysql +```sql select d.id, d.name, e.name as assistant from department as d join employee as e on e.dept = d.id @@ -60,7 +60,7 @@ where e.post = 'assistant' ### C -```mysql +```sql select d.id, d.name, e.name as assistant from department as d cross join employee as e on e.dept = d.id @@ -69,7 +69,7 @@ where e.post = 'assistant' ### D -```mysql +```sql select d.id, d.name, e.name as assistant from employee as e left join department as d on e.dept = 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 bd33e5a..3730519 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" @@ -2,7 +2,7 @@ 现有部门表 -```mysql +```sql create table department( id int primary key auto_increment, name varchar(256) @@ -11,7 +11,7 @@ create table department( 和员工表 -```mysql +```sql create table employee( id int primary key auto_increment, dept_id int, @@ -32,7 +32,7 @@ create table employee( ## 答案 -```mysql +```sql select e.id, e.name, e.dept from department as d right join employee as e on d.id = e.dept @@ -43,7 +43,7 @@ where d.id is null; ### A -```mysql +```sql select e.id, e.name, e.dept from employee as e right join department as d on d.id = e.dept @@ -52,7 +52,7 @@ where e.id is null; ### B -```mysql +```sql select e.id, e.name, e.dept from employee as e right join department as d on d.id = e.dept @@ -61,7 +61,7 @@ where d.id is null; ### C -```mysql +```sql select e.id, e.name, e.dept from department as d join employee as e on d.id = e.dept @@ -71,7 +71,7 @@ where d.id is null; ### D -```mysql +```sql select e.id, e.name, e.dept from department as d right join employee as e on d.id = e.dept 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/4. CROSS JOIN/cross_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/4. CROSS JOIN/cross_join.md" index 654db16..de96047 100644 --- "a/data/2.MySQL\344\270\255\351\230\266/6.\350\277\236\346\216\245\346\237\245\350\257\242/4. CROSS JOIN/cross_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/4. CROSS JOIN/cross_join.md" @@ -2,7 +2,7 @@ Joe 需要生成 goods 表 -```mysql +```sql create table goods( id int primary key auto_increment, category varchar(64), @@ -15,7 +15,7 @@ create table goods( 中所有T恤(category为`T-Shirt`)的所有尺寸,尺寸信息在 size 表 -```mysql +```sql create table size( id int primary key auto_increment, name varchar(16) @@ -33,7 +33,7 @@ create table size( ## 答案 -```mysql +```sql select g.id, g.name, s.name as size from goods as g cross join size as s @@ -44,7 +44,7 @@ where g.category = 'T-Shirt'; ### A -```mysql +```sql select g.id, g.name, s.name as size from goods as g full join size as s @@ -53,7 +53,7 @@ where g.category = 'T-Shirt'; ### B -```mysql +```sql select g.id, g.name, s.name as size from goods as g left join size as s @@ -62,7 +62,7 @@ where g.category = 'T-Shirt'; ### C -```mysql +```sql select g.id, g.name, s.name as size from goods as g left join size as s @@ -71,7 +71,7 @@ where g.category = 'T-Shirt'; ### D -```mysql +```sql select g.id, g.name, s.name as size from goods as g right join size as s @@ -80,7 +80,7 @@ where g.category = 'T-Shirt'; ### E -```mysql +```sql select g.id, g.name, s.name as size from goods as g outter join size as s 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/5. \345\244\215\346\235\202\350\277\236\346\216\245/salary.md" "b/data/2.MySQL\344\270\255\351\230\266/6.\350\277\236\346\216\245\346\237\245\350\257\242/5. \345\244\215\346\235\202\350\277\236\346\216\245/salary.md" index 57a9ec4..785fb56 100644 --- "a/data/2.MySQL\344\270\255\351\230\266/6.\350\277\236\346\216\245\346\237\245\350\257\242/5. \345\244\215\346\235\202\350\277\236\346\216\245/salary.md" +++ "b/data/2.MySQL\344\270\255\351\230\266/6.\350\277\236\346\216\245\346\237\245\350\257\242/5. \345\244\215\346\235\202\350\277\236\346\216\245/salary.md" @@ -2,7 +2,7 @@ 现有员工信息表如下: -```mysql +```sql create table employee ( id serial primary key, @@ -23,7 +23,7 @@ create table employee ## 答案 -```mysql +```sql select l.id, l.name, l.dept, l.salary from employee as l join (select max(salary) as salary, dept @@ -36,7 +36,7 @@ from employee as l ### select 与 group by 不匹配 -```mysql +```sql select id, name, dept, max(salary) from employee group by dept; @@ -44,7 +44,7 @@ group by dept; ### group by 不对 -```mysql +```sql select id, name, dept, max(salary) from employee group by dept, id, name; @@ -52,7 +52,7 @@ group by dept, id, name; ### group by 不对 -```mysql +```sql select id, name, dept, max(salary) from employee group by dept, id, name @@ -61,7 +61,7 @@ having salary = max(salary); ### 结构错误 -```mysql +```sql select id, name, dept, max(salary) from employee where salary = max(salary) 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 04a66f6..abfe688 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" @@ -2,7 +2,7 @@ Joe 想给 Goods 表 -```mysql +```sql create table goods( id int primary key auto_increment, category_id int, @@ -26,7 +26,7 @@ create table goods( ## 答案 -```mysql +```sql create index idx_goods_category on goods(category_id); ``` @@ -34,18 +34,18 @@ create index idx_goods_category on goods(category_id); ### A -```mysql +```sql create unique index idx_goods_category on goods(category_id); ``` ### B -```mysql +```sql create index idx_goods_category on goods(category_id); ``` ### C -```mysql +```sql 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 1514db0..920b344 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" @@ -13,13 +13,13 @@ Joe 想要删除创建在 goods 表创建的索引,但是他已经忘了这个 执行 -```mysql +```sql show index from goods; ``` 查看 goods 表的索引(假设查到是 idx_goods_category),然后执行 -```mysql +```sql alter table goods drop index idx_goods_category; ``` @@ -29,13 +29,13 @@ alter table goods drop index idx_goods_category; 执行 -```mysql +```sql show index from goods; ``` 查看 goods 表的索引(假设查到是 idx_goods_category),然后执行 -```mysql +```sql alter table goods delete index idx_goods_category; ``` @@ -43,13 +43,13 @@ alter table goods delete index idx_goods_category; 执行 -```mysql +```sql show index from goods; ``` 查看 goods 表的索引(假设查到是 idx_goods_category),然后执行 -```mysql +```sql alter table goods remove index idx_goods_category; ``` @@ -57,13 +57,13 @@ alter table goods remove index idx_goods_category; 执行 -```mysql +```sql show index from goods; ``` 查看 goods 表的索引(假设查到是 idx_goods_category),然后执行 -```mysql +```sql 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 4231d4d..f0316a9 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" @@ -2,7 +2,7 @@ Goods 表结构如下: -```mysql +```sql create table goods( id int primary key auto_increment, category_id int, @@ -24,7 +24,7 @@ Joe 需要确保同一个类型下没有重名的商品,他应该怎么做? ## 答案 -```mysql +```sql alter table goods add unique index (category_id, name); ``` @@ -32,18 +32,18 @@ alter table goods add unique index (category_id, name); ### A -```mysql +```sql alter table goods add index (category_id, name); ``` ### B -```mysql +```sql alter table goods add unique index (category_id + name); ``` ### C -```mysql +```sql 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/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 b9cbc89..b98932f 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" @@ -2,7 +2,7 @@ Goods 表结构如下: -```mysql +```sql create table goods( id int primary key auto_increment, category_id int, @@ -24,7 +24,7 @@ create table goods( ## 答案 -```mysql +```sql alter table goods add index (name, price); ``` @@ -38,12 +38,12 @@ alter table goods add index (name, price); 建立一个计算字段: -```mysql +```sql alter table goods add summary varchar(1024) generated always as (concat(name, '(', 0.5, ')')); ``` ### C -```mysql +```sql 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 d35cd8b..2607b91 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" @@ -2,7 +2,7 @@ Goods 表结构如下: -```mysql +```sql create table goods( id int primary key auto_increment, category_id int, @@ -28,7 +28,7 @@ Joe 发现有大量查询 `select id, category_id, name, price from goods where 将该查询改写为 -```mysql +```sql select id, category_id, name, price from goods where category_id=? and name=?; ``` @@ -38,7 +38,7 @@ select id, category_id, name, price from goods where category_id=? and name=?; 将该查询改写为 -```mysql +```sql select id, category_id, name, price from goods where category_id and name= (?, ?); ``` @@ -46,7 +46,7 @@ select id, category_id, name, price from goods where category_id and name= (?, ? 将该查询改写为 -```mysql +```sql select id, category_id, name, price from goods where not (category_id !=? or name != ?); ``` @@ -54,7 +54,7 @@ select id, category_id, name, price from goods where not (category_id !=? or nam 将该查询改写为 -```mysql +```sql 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 0b49bfe..82d1b5a 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" @@ -2,7 +2,7 @@ Goods 表结构如下: -```mysql +```sql create table goods( id int primary key auto_increment, category_id int, @@ -26,7 +26,7 @@ Joe 应该如何优化? ## 答案 -```mysql +```sql alter table goods add index (`stock-id`, category_id, name); ``` @@ -34,18 +34,18 @@ alter table goods add index (`stock-id`, category_id, name); ### A -```mysql +```sql alter table goods add index (`stock-id` and category_id and name); ``` ### B -```mysql +```sql alter table goods add index (concat(stock, category_id, name)); ``` ### C -```mysql +```sql alter table goods add index (`stock-id` + 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/5.\347\251\272\351\227\264\347\264\242\345\274\225/geo_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/5.\347\251\272\351\227\264\347\264\242\345\274\225/geo_index.md" index 67d825c..23cad41 100644 --- "a/data/3.MySQL\351\253\230\351\230\266/1.\346\267\261\345\205\245\347\264\242\345\274\225/5.\347\251\272\351\227\264\347\264\242\345\274\225/geo_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/5.\347\251\272\351\227\264\347\264\242\345\274\225/geo_index.md" @@ -2,7 +2,7 @@ Goods 数据库中有一个 shop 表,其中包含如下字段: -```mysql +```sql create table shop ( id int primary key auto_increment, location GEOMETRY @@ -21,7 +21,7 @@ create table shop ( ## 答案 -```mysql +```sql alter table shop modify location GEOMETRY not null; alter table shop add INDEX geo_index(location); ``` @@ -30,26 +30,26 @@ alter table shop add INDEX geo_index(location); ### A -```mysql +```sql alter table shop add INDEX geo_index(location); ``` ### B -```mysql +```sql alter table shop add INDEX location; ``` ### C -```mysql +```sql alter table shop modify location GEOMETRY not null; alter table shop add INDEX location; ``` ### D -```mysql +```sql alter table shop modify location GEOMETRY not null; alter table shop add INDEX location; ``` 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/6.\345\205\250\346\226\207\347\264\242\345\274\225/full_text_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/6.\345\205\250\346\226\207\347\264\242\345\274\225/full_text_index.md" index ba4ca97..e6fc999 100644 --- "a/data/3.MySQL\351\253\230\351\230\266/1.\346\267\261\345\205\245\347\264\242\345\274\225/6.\345\205\250\346\226\207\347\264\242\345\274\225/full_text_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/6.\345\205\250\346\226\207\347\264\242\345\274\225/full_text_index.md" @@ -2,7 +2,7 @@ Shop 表的部分字段如下: -```mysql +```sql create table shop ( id int primary key auto_increment, description varchar(8000) @@ -21,7 +21,7 @@ create table shop ( ## 答案 -```mysql +```sql alter table shop add fulltext(description); ``` @@ -29,18 +29,18 @@ alter table shop add fulltext(description); ### A -```mysql +```sql alter table shop add index fulltext(description); ``` ### B -```mysql +```sql alter table shop create fulltext(description); ``` ### C -```mysql +```sql alter table shop alter description add fulltext(description); ``` \ 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/7.\351\232\220\350\227\217\347\264\242\345\274\225/invisible.md" "b/data/3.MySQL\351\253\230\351\230\266/1.\346\267\261\345\205\245\347\264\242\345\274\225/7.\351\232\220\350\227\217\347\264\242\345\274\225/invisible.md" index 87a826b..75d122f 100644 --- "a/data/3.MySQL\351\253\230\351\230\266/1.\346\267\261\345\205\245\347\264\242\345\274\225/7.\351\232\220\350\227\217\347\264\242\345\274\225/invisible.md" +++ "b/data/3.MySQL\351\253\230\351\230\266/1.\346\267\261\345\205\245\347\264\242\345\274\225/7.\351\232\220\350\227\217\347\264\242\345\274\225/invisible.md" @@ -2,7 +2,7 @@ Shop 表的部分字段如下: -```mysql +```sql create table shop ( id int primary key auto_increment, description varchar(8000), @@ -27,13 +27,13 @@ Joe 应该怎么做? 先执行 -```mysql +```sql alter table shop alter index description invisible ; ``` 将索引隐藏,观察确认没有影响后再执行 -```mysql +```sql alter table shop drop index description; ``` @@ -46,7 +46,7 @@ alter table shop drop index description; 先备份 shop 表,然后执行 -```mysql +```sql alter table shop drop index description; ``` 删除,有问题的话从备份文件恢复。 @@ -59,13 +59,13 @@ alter table shop drop index description; 先执行 -```mysql +```sql alter table shop alter index description invisible ; ``` 将索引隐藏,确认后再执行 -```mysql +```sql alter table shop alter index description visible ; ``` 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/8.\345\207\275\346\225\260\345\222\214\350\241\250\350\276\276\345\274\217\347\264\242\345\274\225/daily_payment.md" "b/data/3.MySQL\351\253\230\351\230\266/1.\346\267\261\345\205\245\347\264\242\345\274\225/8.\345\207\275\346\225\260\345\222\214\350\241\250\350\276\276\345\274\217\347\264\242\345\274\225/daily_payment.md" index 1be56bb..e55af79 100644 --- "a/data/3.MySQL\351\253\230\351\230\266/1.\346\267\261\345\205\245\347\264\242\345\274\225/8.\345\207\275\346\225\260\345\222\214\350\241\250\350\276\276\345\274\217\347\264\242\345\274\225/daily_payment.md" +++ "b/data/3.MySQL\351\253\230\351\230\266/1.\346\267\261\345\205\245\347\264\242\345\274\225/8.\345\207\275\346\225\260\345\222\214\350\241\250\350\276\276\345\274\217\347\264\242\345\274\225/daily_payment.md" @@ -2,7 +2,7 @@ 数据分析组需要经常执行以下查询生成从昨天到之前某一天的交易量统计 -```mysql +```sql select date(payment_date) as day, sum(amount) from payment where date(payment_date) between $1 and DATE_SUB(CURDATE(), INTERVAL 1 DAY) @@ -39,7 +39,7 @@ mysql> desc payment; 建立表达式索引 -```mysql +```sql alter table payment add index idx_payment_date((date(payment_date))); ``` @@ -49,13 +49,13 @@ alter table payment add index idx_payment_date((date(payment_date))); 建立视图 -```mysql +```sql create view view_daily_payment as select date(payment_date) as day, amount from payment; ``` 然后在视图 view_daily_payment 上执行 -```mysql +```sql select day, sum(amount) from view_daily_payment where day between $1 and DATE_SUB(CURDATE(), INTERVAL 1 DAY) @@ -66,7 +66,7 @@ group by day 在 payment_date 列上建立索引 -```mysql +```sql create index idx_payment_date on payment(payment_date); ``` @@ -74,13 +74,13 @@ create index idx_payment_date on payment(payment_date); 建立计算列 -```mysql +```sql alter table payment add day date generated always as (date(payment_date)) stored; ``` 然后使用它改写查询 -```mysql +```sql select day as day, sum(amount) from payment where day between $1 and date('yesterday') diff --git "a/data/3.MySQL\351\253\230\351\230\266/2.SQL\351\253\230\347\272\247\346\212\200\345\267\247/1.CTE\345\222\214\351\200\222\345\275\222\346\237\245\350\257\242/continuous.md" "b/data/3.MySQL\351\253\230\351\230\266/2.SQL\351\253\230\347\272\247\346\212\200\345\267\247/1.CTE\345\222\214\351\200\222\345\275\222\346\237\245\350\257\242/continuous.md" index bda945b..57c0ab4 100644 --- "a/data/3.MySQL\351\253\230\351\230\266/2.SQL\351\253\230\347\272\247\346\212\200\345\267\247/1.CTE\345\222\214\351\200\222\345\275\222\346\237\245\350\257\242/continuous.md" +++ "b/data/3.MySQL\351\253\230\351\230\266/2.SQL\351\253\230\347\272\247\346\212\200\345\267\247/1.CTE\345\222\214\351\200\222\345\275\222\346\237\245\350\257\242/continuous.md" @@ -3,7 +3,7 @@ SmartMarket 交易所的系统中,所有订单在生成时,都从一个 oracle Sequence 中获取唯一的 序列号,完成交易计算后各个撮合程序将其插入如下的 orders 表中: -```mysql +```sql create table orders ( id integer primary key, @@ -27,7 +27,7 @@ create table orders ## 答案 -```mysql +```sql with recursive r(id) as (select id from orders where id = $1 @@ -48,7 +48,7 @@ from orders ### B -```mysql +```sql select data.id, content from orders join orders as r on orders.id = r.id - 1 @@ -57,7 +57,7 @@ where id = $1; ### C -```mysql +```sql select id, content from orders where id in (select id from orders where id = id + 1); @@ -65,7 +65,7 @@ where id in (select id from orders where id = id + 1); ### D -```mysql +```sql with r as (select id from orders where id = $1 diff --git "a/data/3.MySQL\351\253\230\351\230\266/2.SQL\351\253\230\347\272\247\346\212\200\345\267\247/1.CTE\345\222\214\351\200\222\345\275\222\346\237\245\350\257\242/to_root.md" "b/data/3.MySQL\351\253\230\351\230\266/2.SQL\351\253\230\347\272\247\346\212\200\345\267\247/1.CTE\345\222\214\351\200\222\345\275\222\346\237\245\350\257\242/to_root.md" index f59b0df..353900b 100644 --- "a/data/3.MySQL\351\253\230\351\230\266/2.SQL\351\253\230\347\272\247\346\212\200\345\267\247/1.CTE\345\222\214\351\200\222\345\275\222\346\237\245\350\257\242/to_root.md" +++ "b/data/3.MySQL\351\253\230\351\230\266/2.SQL\351\253\230\347\272\247\346\212\200\345\267\247/1.CTE\345\222\214\351\200\222\345\275\222\346\237\245\350\257\242/to_root.md" @@ -2,7 +2,7 @@ 现有一个表 node -```mysql +```sql create table node ( id int primary key auto_increment, @@ -24,7 +24,7 @@ create table node ## 答案 -```mysql +```sql with recursive t(id, pid, val) as ( select id, pid, val from node @@ -42,7 +42,7 @@ from node ### 没有递归定义 -```mysql +```sql with t as ( select id, pid, val from node @@ -58,7 +58,7 @@ from node ### 平凡的连接查询无法处理递归问题 -```mysql +```sql select node.id, node.pid, node.val from node join node as p on node.pid = p.id @@ -67,7 +67,7 @@ where id = $1; ### 子查询无法处理递归问题 -```mysql +```sql select node.id, node.pid, node val from node as t where t.pid = (select id from t where id = t.pid) diff --git "a/data/3.MySQL\351\253\230\351\230\266/2.SQL\351\253\230\347\272\247\346\212\200\345\267\247/2.Window Function/salary.md" "b/data/3.MySQL\351\253\230\351\230\266/2.SQL\351\253\230\347\272\247\346\212\200\345\267\247/2.Window Function/salary.md" index 7a203ad..f312bcf 100644 --- "a/data/3.MySQL\351\253\230\351\230\266/2.SQL\351\253\230\347\272\247\346\212\200\345\267\247/2.Window Function/salary.md" +++ "b/data/3.MySQL\351\253\230\351\230\266/2.SQL\351\253\230\347\272\247\346\212\200\345\267\247/2.Window Function/salary.md" @@ -2,7 +2,7 @@ 现有员工信息表如下: -```mysql +```sql create table employee ( id serial primary key, @@ -23,7 +23,7 @@ create table employee ## 答案 -```mysql +```sql select id, name, dept, salary from (select id, name, dept, salary, rank() over (partition by dept order by salary desc) as r from employee) as t @@ -34,7 +34,7 @@ where r <= 5; ### 结构错误 -```mysql +```sql select id, name, dept, max(salary) as salary from employee group by dept @@ -43,7 +43,7 @@ having id < 6; ### 结构错误 -```mysql +```sql select l.id, l.name, l.dept, l.salary from employee as l join (select max(salary) as salary, dept @@ -55,7 +55,7 @@ where count(r.id) <= 5; ### 结构错误 -```mysql +```sql select l.id, l.name, l.dept, l.salary from employee as l join (select max(salary, 5) as salary, dept @@ -66,7 +66,7 @@ from employee as l ### 结构错误 -```mysql +```sql select id, name, dept, salary, rank() over (partition by dept order by salary desc) as r from employee where r <= 5; @@ -74,7 +74,7 @@ where r <= 5; ### 结构错误 -```mysql +```sql select id, name, dept, salary, rank() as r over (partition by dept order by salary desc) from employee where r <= 5; diff --git "a/data/3.MySQL\351\253\230\351\230\266/2.SQL\351\253\230\347\272\247\346\212\200\345\267\247/3.\351\200\217\350\247\206\350\241\250 /pivot.md" "b/data/3.MySQL\351\253\230\351\230\266/2.SQL\351\253\230\347\272\247\346\212\200\345\267\247/3.\351\200\217\350\247\206\350\241\250 /pivot.md" index c4bf9f7..122e390 100644 --- "a/data/3.MySQL\351\253\230\351\230\266/2.SQL\351\253\230\347\272\247\346\212\200\345\267\247/3.\351\200\217\350\247\206\350\241\250 /pivot.md" +++ "b/data/3.MySQL\351\253\230\351\230\266/2.SQL\351\253\230\347\272\247\346\212\200\345\267\247/3.\351\200\217\350\247\206\350\241\250 /pivot.md" @@ -2,7 +2,7 @@ 现有销售记录表 -```mysql +```sql create table sales( id serial primary key , sku_id integer not null , @@ -23,7 +23,7 @@ create index on sales(created_at); ## 答案 -```mysql +```sql select sku_id, sum(case extract(month from created_at) when 1 then amount else 0 end) as Jan, sum(case extract(month from created_at) when 2 then amount else 0 end) as Feb, @@ -46,7 +46,7 @@ group by sku_id; ### 格式不相符 -```mysql +```sql select sku_id, extract(month from created_at) as month, sum(amount) from sales where created_at between '2020-01-01'::timestamp and '2021-01-01'::timestamp @@ -55,7 +55,7 @@ group by 1, 2; ### 计算逻辑错误 -```mysql +```sql select sku_id, sum(amount) as Jan, sum(amount) as Feb, @@ -76,7 +76,7 @@ group by sku_id, extract(month from created_at); ### 计算格式错误 -```mysql +```sql select sku_id, sum(amount having extract(month from created_at) = 1) as Jan, sum(amount having extract(month from created_at) = 2) as Feb, diff --git "a/data/3.MySQL\351\253\230\351\230\266/2.SQL\351\253\230\347\272\247\346\212\200\345\267\247/4.Double Not Exists/DoubleNotExists.md" "b/data/3.MySQL\351\253\230\351\230\266/2.SQL\351\253\230\347\272\247\346\212\200\345\267\247/4.Double Not Exists/DoubleNotExists.md" index 8a2d1b9..7f85ef9 100644 --- "a/data/3.MySQL\351\253\230\351\230\266/2.SQL\351\253\230\347\272\247\346\212\200\345\267\247/4.Double Not Exists/DoubleNotExists.md" +++ "b/data/3.MySQL\351\253\230\351\230\266/2.SQL\351\253\230\347\272\247\346\212\200\345\267\247/4.Double Not Exists/DoubleNotExists.md" @@ -2,7 +2,7 @@ 风控部门的数据库中有一组关于招投标的数据,关键信息如下: -```mysql +```sql -- 招标项目 create table invitation ( @@ -42,7 +42,7 @@ Joe 想要找出参与了所有投标的企业(有围标嫌疑),那么这 ## 答案 -```mysql +```sql select * from company where not exists( @@ -61,7 +61,7 @@ where not exists( ### A -```mysql +```sql select * from company where id = all (select company_id @@ -70,7 +70,7 @@ where id = all (select company_id ### B -```mysql +```sql select * from company where id = any (select company_id @@ -79,7 +79,7 @@ where id = any (select company_id ### C -```mysql +```sql select * from company where company.id in (select distinct company_id from bids) @@ -87,7 +87,7 @@ where company.id in (select distinct company_id from bids) ### D -```mysql +```sql select * from company where exists( diff --git "a/data/3.MySQL\351\253\230\351\230\266/2.SQL\351\253\230\347\272\247\346\212\200\345\267\247/5.\345\206\231\345\205\245\345\222\214\345\206\262\347\252\201/score.md" "b/data/3.MySQL\351\253\230\351\230\266/2.SQL\351\253\230\347\272\247\346\212\200\345\267\247/5.\345\206\231\345\205\245\345\222\214\345\206\262\347\252\201/score.md" index c4e5b1b..638391a 100644 --- "a/data/3.MySQL\351\253\230\351\230\266/2.SQL\351\253\230\347\272\247\346\212\200\345\267\247/5.\345\206\231\345\205\245\345\222\214\345\206\262\347\252\201/score.md" +++ "b/data/3.MySQL\351\253\230\351\230\266/2.SQL\351\253\230\347\272\247\346\212\200\345\267\247/5.\345\206\231\345\205\245\345\222\214\345\206\262\347\252\201/score.md" @@ -2,7 +2,7 @@ 现有一个表 -```mysql +```sql create table book_in( login integer primary key , score integer default 0 @@ -21,7 +21,7 @@ create table book_in( ## 答案 -```mysql +```sql insert into book_in(login, score) values ($1, $2) on DUPLICATE KEY update score=$2; ``` @@ -29,7 +29,7 @@ insert into book_in(login, score) values ($1, $2) on DUPLICATE KEY update score= ### A -```mysql +```sql try insert into book_in(login, score) values ($1, $2); catch @@ -40,18 +40,18 @@ finally ### B -```mysql +```sql insert into book_in(login, score) select $1, $2; ``` ### C -```mysql +```sql replace book_in(login, score) select $1, $2; ``` ### D -```mysql +```sql upsert into book_in(login, score) select $1, $2; ``` diff --git "a/data/3.MySQL\351\253\230\351\230\266/2.SQL\351\253\230\347\272\247\346\212\200\345\267\247/6.\344\272\213\345\212\241/transaction.md" "b/data/3.MySQL\351\253\230\351\230\266/2.SQL\351\253\230\347\272\247\346\212\200\345\267\247/6.\344\272\213\345\212\241/transaction.md" index 3347a01..c54633c 100644 --- "a/data/3.MySQL\351\253\230\351\230\266/2.SQL\351\253\230\347\272\247\346\212\200\345\267\247/6.\344\272\213\345\212\241/transaction.md" +++ "b/data/3.MySQL\351\253\230\351\230\266/2.SQL\351\253\230\347\272\247\346\212\200\345\267\247/6.\344\272\213\345\212\241/transaction.md" @@ -2,13 +2,13 @@ 现有 test1 表如下 -```mysql +```sql create table test1(a integer primary key ); ``` 我们执行下面的语句 -```mysql +```sql CREATE PROCEDURE transaction_test1() BEGIN declare idx int; diff --git "a/data/3.MySQL\351\253\230\351\230\266/3. \350\277\207\347\250\213\345\214\226\347\274\226\347\250\213/1.IF/if.md" "b/data/3.MySQL\351\253\230\351\230\266/3. \350\277\207\347\250\213\345\214\226\347\274\226\347\250\213/1.IF/if.md" index d280047..b5d5b99 100644 --- "a/data/3.MySQL\351\253\230\351\230\266/3. \350\277\207\347\250\213\345\214\226\347\274\226\347\250\213/1.IF/if.md" +++ "b/data/3.MySQL\351\253\230\351\230\266/3. \350\277\207\347\250\213\345\214\226\347\274\226\347\250\213/1.IF/if.md" @@ -17,7 +17,7 @@ Goods 数据库中有一个名为 trade 的存储过程,封装了交易过程 ## 答案 -```mysql +```sql set @counter = @counter + 1; if @counter % 1000 = 0 then set @total_price = @total_price * 0.8; @@ -28,7 +28,7 @@ end if; ### A -```mysql +```sql set @counter = @counter + 1; if @counter % 1000 = 0 { set @total_price = @total_price * 0.8; @@ -37,7 +37,7 @@ if @counter % 1000 = 0 { ### B -```mysql +```sql set @counter = @counter + 1; if (@counter % 1000 = 0) { set @total_price = @total_price * 0.8; @@ -46,7 +46,7 @@ if (@counter % 1000 = 0) { ### C -```mysql +```sql if @counter % 1000 = 0 begin ; set @total_price = @total_price * 0.8; end; @@ -54,7 +54,7 @@ end; ### D -```mysql +```sql set @counter ++; if @counter % 1000 = 0 then begin select @total_price = @total_price * 0.8; diff --git "a/data/3.MySQL\351\253\230\351\230\266/3. \350\277\207\347\250\213\345\214\226\347\274\226\347\250\213/2.LOOP/loop.md" "b/data/3.MySQL\351\253\230\351\230\266/3. \350\277\207\347\250\213\345\214\226\347\274\226\347\250\213/2.LOOP/loop.md" index d51bd95..04771a8 100644 --- "a/data/3.MySQL\351\253\230\351\230\266/3. \350\277\207\347\250\213\345\214\226\347\274\226\347\250\213/2.LOOP/loop.md" +++ "b/data/3.MySQL\351\253\230\351\230\266/3. \350\277\207\347\250\213\345\214\226\347\274\226\347\250\213/2.LOOP/loop.md" @@ -13,7 +13,7 @@ ## 答案 -```mysql +```sql -- ... trade: LOOP if @price > 1000 then @@ -33,7 +33,7 @@ end LOOP trace; ### A -```mysql +```sql -- ... trade: LOOP if @price > 1000 then @@ -49,7 +49,7 @@ end LOOP trace; ### B -```mysql +```sql -- ... trade: LOOP if @price > 1000 then @@ -67,7 +67,7 @@ end LOOP trace; ### C -```mysql +```sql -- ... trade: LOOP if @price > 1000 then @@ -85,7 +85,7 @@ end LOOP trace; ### D -```mysql +```sql -- ... trade: LOOP if @price > 1000 then diff --git "a/data/3.MySQL\351\253\230\351\230\266/3. \350\277\207\347\250\213\345\214\226\347\274\226\347\250\213/3.REPEAT/repeat.md" "b/data/3.MySQL\351\253\230\351\230\266/3. \350\277\207\347\250\213\345\214\226\347\274\226\347\250\213/3.REPEAT/repeat.md" index 8750cc6..8916c5e 100644 --- "a/data/3.MySQL\351\253\230\351\230\266/3. \350\277\207\347\250\213\345\214\226\347\274\226\347\250\213/3.REPEAT/repeat.md" +++ "b/data/3.MySQL\351\253\230\351\230\266/3. \350\277\207\347\250\213\345\214\226\347\274\226\347\250\213/3.REPEAT/repeat.md" @@ -2,7 +2,7 @@ 交易过程 trade 中有一个遍历交易项的循环,当累计的总交易额 `@total_price` 超过 20000, 这个循环就结束 -```mysql +```sql -- ... trade: LOOP -- ... @@ -26,7 +26,7 @@ end LOOP trace; ## 答案 -```mysql +```sql trade: REPEATE -- 省略交易过程 UNTIL @total_price > 20000 @@ -37,7 +37,7 @@ END REPATE trade; ### A -```mysql +```sql trade: REPEATE UNTIL @total_price > 20000 -- 省略交易过程 @@ -46,7 +46,7 @@ END REPATE trade; ### B -```mysql +```sql REPEATE @total_price > 20000 -- 省略交易过程 END REPATE; @@ -54,7 +54,7 @@ END REPATE; ### C -```mysql +```sql trade: REPEATE -- 省略交易过程 IF @total_price > 20000 @@ -63,7 +63,7 @@ END REPATE trade; ### D -```mysql +```sql trade: REPEATE IF @total_price > 20000 -- 省略交易过程 diff --git "a/data/3.MySQL\351\253\230\351\230\266/3. \350\277\207\347\250\213\345\214\226\347\274\226\347\250\213/4.WHILE/while.md" "b/data/3.MySQL\351\253\230\351\230\266/3. \350\277\207\347\250\213\345\214\226\347\274\226\347\250\213/4.WHILE/while.md" index b9354cc..9e4ecd0 100644 --- "a/data/3.MySQL\351\253\230\351\230\266/3. \350\277\207\347\250\213\345\214\226\347\274\226\347\250\213/4.WHILE/while.md" +++ "b/data/3.MySQL\351\253\230\351\230\266/3. \350\277\207\347\250\213\345\214\226\347\274\226\347\250\213/4.WHILE/while.md" @@ -2,7 +2,7 @@ 交易过程 trade 中有一个遍历交易项的循环,当累计的总交易额 `@total_price` 超过 20000, 这个循环就结束 -```mysql +```sql -- ... trade: LOOP -- ... @@ -26,7 +26,7 @@ end LOOP trace; ## 答案 -```mysql +```sql trade: WHILE @total_price > 20000 -- 省略交易过程 END WHILE trade; @@ -36,7 +36,7 @@ END WHILE trade; ### A -```mysql +```sql trade: DO -- 省略交易过程 WHILE @total_price > 20000; @@ -44,7 +44,7 @@ WHILE @total_price > 20000; ### B -```mysql +```sql trade: WHILE @total_price > 20000 -- 省略交易过程 END WHILE trade; @@ -52,7 +52,7 @@ END WHILE trade; ### C -```mysql +```sql trade: WHILE @total_price > 20000 DO -- 省略交易过程 END WHILE trade; @@ -60,7 +60,7 @@ END WHILE trade; ### D -```mysql +```sql trade: WHILE @total_price > 20000 -- 省略交易过程 END WHILE; diff --git "a/data/3.MySQL\351\253\230\351\230\266/3. \350\277\207\347\250\213\345\214\226\347\274\226\347\250\213/5. \346\270\270\346\240\207/cursor.md" "b/data/3.MySQL\351\253\230\351\230\266/3. \350\277\207\347\250\213\345\214\226\347\274\226\347\250\213/5. \346\270\270\346\240\207/cursor.md" index a12cedf..841c6d4 100644 --- "a/data/3.MySQL\351\253\230\351\230\266/3. \350\277\207\347\250\213\345\214\226\347\274\226\347\250\213/5. \346\270\270\346\240\207/cursor.md" +++ "b/data/3.MySQL\351\253\230\351\230\266/3. \350\277\207\347\250\213\345\214\226\347\274\226\347\250\213/5. \346\270\270\346\240\207/cursor.md" @@ -2,7 +2,7 @@ Joe 需要开发一个存储过程 make_trade,从 orders 表 -```mysql +```sql create table orders ( id int primary key auto_increment, price decimal(12, 4), @@ -13,7 +13,7 @@ create table orders ( 中,按 id 从小到大加载订单数据,生成交易单,写入 trade 表 -```mysql +```sql create table trade ( id int primary key auto_increment, total decimal(12, 4) @@ -36,7 +36,7 @@ create table trade ( ## 答案 -```mysql +```sql create procedure make_trade() begin DECLARE done INT DEFAULT FALSE; @@ -70,7 +70,7 @@ end; ### A -```mysql +```sql create procedure make_trade() begin DECLARE done INT DEFAULT FALSE; @@ -97,7 +97,7 @@ end; ### B -```mysql +```sql create procedure make_trade() begin declare cur_orders cursor for select id, price, item_id, amount from orders order by id limit 1000; @@ -118,7 +118,7 @@ end; ### C -```mysql +```sql create procedure make_trade() begin DECLARE done INT DEFAULT FALSE; @@ -139,7 +139,7 @@ end; ### D -```mysql +```sql create procedure make_trade() begin DECLARE done INT DEFAULT FALSE; diff --git "a/data/3.MySQL\351\253\230\351\230\266/4.\350\256\276\350\256\241\344\274\230\345\214\226/1.\347\224\237\346\210\220\345\210\227/generated.md" "b/data/3.MySQL\351\253\230\351\230\266/4.\350\256\276\350\256\241\344\274\230\345\214\226/1.\347\224\237\346\210\220\345\210\227/generated.md" index 0683aaa..7354211 100644 --- "a/data/3.MySQL\351\253\230\351\230\266/4.\350\256\276\350\256\241\344\274\230\345\214\226/1.\347\224\237\346\210\220\345\210\227/generated.md" +++ "b/data/3.MySQL\351\253\230\351\230\266/4.\350\256\276\350\256\241\344\274\230\345\214\226/1.\347\224\237\346\210\220\345\210\227/generated.md" @@ -2,7 +2,7 @@ Joe 需要为 Points 表 -```mysql +```sql create table points( id int primary key auto_increment, x float, @@ -21,7 +21,7 @@ create table points( ## 答案 -```mysql +```sql alter table points add modulus double generated always as (sqrt(x*x + y*y)); ``` @@ -29,18 +29,18 @@ alter table points add modulus double generated always as (sqrt(x*x + y*y)); ### A -```mysql +```sql create generated modulus on table points as (sqrt(x*x + y*y)); ``` ### B -```mysql +```sql alter table points add modulus generated always as (sqrt(x*x + y*y)); ``` ### C -```mysql +```sql alter table points add modulus float generated sqrt(x*x + y*y); ``` diff --git "a/data/3.MySQL\351\253\230\351\230\266/4.\350\256\276\350\256\241\344\274\230\345\214\226/2. \350\214\203\345\274\217\350\256\276\350\256\241/customer_order.md" "b/data/3.MySQL\351\253\230\351\230\266/4.\350\256\276\350\256\241\344\274\230\345\214\226/2. \350\214\203\345\274\217\350\256\276\350\256\241/customer_order.md" index e57beef..d669793 100644 --- "a/data/3.MySQL\351\253\230\351\230\266/4.\350\256\276\350\256\241\344\274\230\345\214\226/2. \350\214\203\345\274\217\350\256\276\350\256\241/customer_order.md" +++ "b/data/3.MySQL\351\253\230\351\230\266/4.\350\256\276\350\256\241\344\274\230\345\214\226/2. \350\214\203\345\274\217\350\256\276\350\256\241/customer_order.md" @@ -2,7 +2,7 @@ Goods 中有客户/订单系统如下: -```mysql +```sql create table customers ( id serial primary key, diff --git "a/data/3.MySQL\351\253\230\351\230\266/4.\350\256\276\350\256\241\344\274\230\345\214\226/4.\345\242\236\345\212\240\344\270\255\351\227\264\350\241\250/daily_payment2.md" "b/data/3.MySQL\351\253\230\351\230\266/4.\350\256\276\350\256\241\344\274\230\345\214\226/4.\345\242\236\345\212\240\344\270\255\351\227\264\350\241\250/daily_payment2.md" index b7cb16f..7df9cde 100644 --- "a/data/3.MySQL\351\253\230\351\230\266/4.\350\256\276\350\256\241\344\274\230\345\214\226/4.\345\242\236\345\212\240\344\270\255\351\227\264\350\241\250/daily_payment2.md" +++ "b/data/3.MySQL\351\253\230\351\230\266/4.\350\256\276\350\256\241\344\274\230\345\214\226/4.\345\242\236\345\212\240\344\270\255\351\227\264\350\241\250/daily_payment2.md" @@ -3,7 +3,7 @@ # 每日报表 分析过去一段时间的查询数据,Joe 发现 payment 表 -```mysql +```sql create table payment( payment_id int primary key auto_increment, customer_id int, @@ -16,7 +16,7 @@ create table payment( 每天的订单量很大,下面这个查询的统计过程占用了大多数数据库资源,查询不会 早于当天,总是在历史上某一个日期段内查询 -```mysql +```sql select date(payment_date) as day, sum(amount) from payment where date(payment_date) between $1 and $2 @@ -47,13 +47,13 @@ select payment_date::date as day, sum(amount) as amount from payment group by da 使用 -```mysql +```sql select day, amount from view_daily_payment where day between $1 and $2; ``` 进行查询。并且每天定时执行一次刷新命令 -```mysql +```sql insert into daily_payment(day, amount) select date(payment_date) as day, sum(amount) as amount from payment @@ -68,7 +68,7 @@ group by day; 在 payment_date 列上建立索引 -```mysql +```sql create index idx_payment_date on payment(payment_date); ``` @@ -76,13 +76,13 @@ create index idx_payment_date on payment(payment_date); 建立计算列 -```mysql +```sql alter table payment add day date generated always as ( payment_date::date ) stored ``` 然后使用它改写查询 -```mysql +```sql select day as day, sum(amount) from payment where day between $1 and DATE_SUB(CURDATE(), INTERVAL 1 DAY) @@ -93,7 +93,7 @@ group by day; 建立表达式索引 -```mysql +```sql create index idx_payment_day on payment((date(payment_date))); ``` @@ -101,13 +101,13 @@ create index idx_payment_day on payment((date(payment_date))); 建立视图 -```mysql +```sql create view view_daily_payment as select date(payment_date) as day, amount from payment; ``` 然后在视图 view_daily_payment 上执行 -```mysql +```sql select day, sum(amount) from view_daily_payment where day between $1 and date('yesterday') diff --git "a/data/3.MySQL\351\253\230\351\230\266/5.\350\277\220\347\273\264\344\270\216\346\236\266\346\236\204/6.\345\244\215\345\210\266\350\277\207\346\273\244\345\231\250/filter.md" "b/data/3.MySQL\351\253\230\351\230\266/5.\350\277\220\347\273\264\344\270\216\346\236\266\346\236\204/6.\345\244\215\345\210\266\350\277\207\346\273\244\345\231\250/filter.md" index 2c815ab..796cae3 100644 --- "a/data/3.MySQL\351\253\230\351\230\266/5.\350\277\220\347\273\264\344\270\216\346\236\266\346\236\204/6.\345\244\215\345\210\266\350\277\207\346\273\244\345\231\250/filter.md" +++ "b/data/3.MySQL\351\253\230\351\230\266/5.\350\277\220\347\273\264\344\270\216\346\236\266\346\236\204/6.\345\244\215\345\210\266\350\277\207\346\273\244\345\231\250/filter.md" @@ -19,7 +19,7 @@ 可以在主库中执行以下命令设定只复制 goods 数据库和 auth 数据库 -```mysql +```sql SET GLOBAL binlog-do-db=goods,auth; ``` @@ -35,7 +35,7 @@ binlog-do-db=goods,auth 可以在从库执行以下命令,设定只复制 goods 数据库和 auth 数据库 -```mysql +```sql SET GLOBAL replicate-do-db=goods,auth; ``` @@ -43,7 +43,7 @@ SET GLOBAL replicate-do-db=goods,auth; 可以在从库执行以下命令,设定只复制 goods 数据库和 auth 数据库 -```mysql +```sql CHANGE REPLICATION FILTER REPLICATE-DO-DB=(goods, order); ``` @@ -59,7 +59,7 @@ replicate-do-db=goods,order; 可以在主库中执行以下命令设定忽略 goods 数据库和 auth 数据库 -```mysql +```sql SET GLOBAL binlog-ignore-db=goods,auth; ``` @@ -75,7 +75,7 @@ binlog-ignore-db=goods,auth 可以在从库执行以下命令,设定忽略 goods 数据库和 auth 数据库 -```mysql +```sql SET GLOBAL replicate-ignore-db=goods,auth; ``` @@ -83,7 +83,7 @@ SET GLOBAL replicate-ignore-db=goods,auth; 可以在从库执行以下命令,设定忽略 goods 数据库和 auth 数据库 -```mysql +```sql CHANGE REPLICATION FILTER REPLICATE_IGNORE_DB=(goods, auth); ``` @@ -99,7 +99,7 @@ replicate-ignore-db=goods,order; 可以在在从库的 MySQL 命令行设定只同步 goods 表和 orders 表 -```mysql +```sql SET GLOBAL replicate-do-table=goods.goods,goods.orders; ``` @@ -107,7 +107,7 @@ SET GLOBAL replicate-do-table=goods.goods,goods.orders; 可以在在从库的 MySQL 命令行设定只同步 goods 表和 orders 表 -```mysql +```sql CHANGE REPLICATION FILTER REPLICATE_DO_TABLE=( goods.goods,goods.orders); ``` @@ -123,7 +123,7 @@ replicate-do-table=goods.goods,goods.orders 可以在在从库的 MySQL 命令行设定只同步名称前缀为 `t_` 的表 -```mysql +```sql CHANGE REPLICATION FILTER REPLICATE_WILD_DO_TABLE =( goods.t_%); ``` @@ -131,7 +131,7 @@ CHANGE REPLICATION FILTER REPLICATE_WILD_DO_TABLE =( goods.t_%); 可以在从库的 MySQL 命令行设定忽略 orders 和 trade 表 -```mysql +```sql SET GLOBAL replicate-ignore-table=goods.orders,goods.trade; ``` @@ -139,7 +139,7 @@ SET GLOBAL replicate-ignore-table=goods.orders,goods.trade; 可以在从库的 MySQL 命令行设定忽略 orders 和 trade 表 -```mysql +```sql CHANGE REPLICATION FILTER REPLICATE_ IGNORE_TABLE=( goods.orders,goods.trade); ``` @@ -156,7 +156,7 @@ replicate-ignore-table =goods.orders,goods.trade 可以在在从库的 MySQL 命令行设定忽略名称前缀为 `o_` 的表 -```mysql +```sql CHANGE REPLICATION FILTER REPLICATE_WILD_DO_TABLE =( goods.o_%); ``` @@ -164,6 +164,6 @@ CHANGE REPLICATION FILTER REPLICATE_WILD_DO_TABLE =( goods.o_%); 设定过滤器时,可以指定通道,例如 -```mysql +```sql CHANGE REPLICATION FILTER REPLICATE-DO-DB=(goods, auth) FOR CHANNEL ‘channel-name’; ``` \ No newline at end of file diff --git "a/data/3.MySQL\351\253\230\351\230\266/6.\346\237\245\350\257\242\344\274\230\345\214\226/1. SHOW STATUS/show_status.md" "b/data/3.MySQL\351\253\230\351\230\266/6.\346\237\245\350\257\242\344\274\230\345\214\226/1. SHOW STATUS/show_status.md" index 8f98a8e..6ec609b 100644 --- "a/data/3.MySQL\351\253\230\351\230\266/6.\346\237\245\350\257\242\344\274\230\345\214\226/1. SHOW STATUS/show_status.md" +++ "b/data/3.MySQL\351\253\230\351\230\266/6.\346\237\245\350\257\242\344\274\230\345\214\226/1. SHOW STATUS/show_status.md" @@ -11,7 +11,7 @@ Goods 数据库近期在每日高峰时段很慢,Joe 想初步的查看一下 ## 答案 -```mysql +```sql show global status; ``` @@ -19,19 +19,19 @@ show global status; ### A -```mysql +```sql show status; ``` ### B -```mysql +```sql show session status; ``` ### C -```mysql +```sql show local status; ``` diff --git "a/data/3.MySQL\351\253\230\351\230\266/6.\346\237\245\350\257\242\344\274\230\345\214\226/3. EXPLAIN/explain.md" "b/data/3.MySQL\351\253\230\351\230\266/6.\346\237\245\350\257\242\344\274\230\345\214\226/3. EXPLAIN/explain.md" index 38c6848..a1b0296 100644 --- "a/data/3.MySQL\351\253\230\351\230\266/6.\346\237\245\350\257\242\344\274\230\345\214\226/3. EXPLAIN/explain.md" +++ "b/data/3.MySQL\351\253\230\351\230\266/6.\346\237\245\350\257\242\344\274\230\345\214\226/3. EXPLAIN/explain.md" @@ -2,7 +2,7 @@ Joe 从交易服务中发现了一些高频查询和慢查询,例如 -```mysql +```sql with recursive r(id) as (select id from orders where id = $1 @@ -28,7 +28,7 @@ from orders 在测试库使用 -```mysql +```sql explain with recursive r(id) as (select id from orders where id = $1 @@ -43,7 +43,7 @@ from orders 进行剖分,对于需要了解详细执行计划的使用 -```mysql +```sql explain analyze with recursive r(id) as (select id from orders where id = 100 @@ -72,7 +72,7 @@ from orders 使用 -```mysql +```sql analyze with recursive r(id) as (select id from orders where id = 100 -- GitLab