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 91162238a9f57f47663becc34854888370ffe89e..ad32a0e7e9abd27900afbb6bc4ca45c063c62ce0 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 65a249c5fd62df68c265b3545e4965005c0cd8f8..cd467b837d9aff9c00aca616c110ea187c77c8c7 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 6019961d1cfb64286606d25627053a06e186bda9..5cbdc4cac52028857f45985815bd969a5af786c5 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 be70f68dabc4df12ad1b615c236218d8ce4b9b4f..569b6ae69573ecffb324899ec3cf8ab0fdb1aa21 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 355a419d3f1c3d39443ee59f62423c3cd855318d..71dbc194b59bade4202b138cb919953549109804 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 3b4869975483a1df8b0a63990ea45b029d80c4c2..1f789b7300c7651548c50c695257c220ac2a1b2d 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 9546a9c27c611aafb5c1ac03fd22fff357168f87..95581d499b6c12a744c713cffef9ed25fad77a5d 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 e93781df5847fc4a70215393fcbd7633a01ad60e..0b0b99bad86504d701c3025ca5c0ed6edd57383a 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 a41eaff16b4f80b77fb8253a8a68454b9ef2643b..9ccc0956a7597819304fdeee79ac3c49bb1ee41f 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 d703b8ab5a68c9c14af8ecf091757cd1954e63bd..1d521a439162bce5dd9df3e1d8ced58abfa1eb1c 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 3465818a4fa72ca34bf2e5ab67423a34e7c1ca84..56258b1debe899d59cb9b0fff8d2925aae86b5d5 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 abcf1961c02d335e64ad3fe5c4e3c5509f40888a..a1d73279ebf455eb72e04713708b0092c6431ba5 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 7397bbcda220c6ee972eb74bc7d0c14ff96439eb..7571ad4998992accc93719b2dbdfc34352420691 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 042dd90975f68c122c152f0cfb1c6ee425007593..cb25e6d5d2d7f23bdb2944bc7fc9987f02874e92 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 0e755a92f70d0792b96af8ab85a2de7af0422722..4b282d61c0e7ca8624f1b7d6f0b444bd0e6bbd6d 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 6345f34c2303f440a4f43ca9b3f12b119fdf60e7..1bc5e9690dba7d956497f5be4f1d71bf3d7e7c82 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 a7cae2ddf873375d85ac49aa9b70cbcbe05ca0c8..e67a6f49808195a52b238bee5993e8381cba00ef 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 12e91aa6e682d44fff65f1729cdedd8c05650225..3c9bc8025e1d909b33aff3c992aba51601b853f0 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 16b01a89c1cca4ec6bdca4d35fe3b2bc0a46d3b8..dc50d73ae6b41241575f0ad87accdaaad59c512a 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 ed1c286d470e80154916ea16bfe7ca6e14ae0ad4..2f663f7b9a058a02f93968bde2ad2e86cf59a155 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 86d19fd3882e0a458ea171992eca02e3122bf572..bf713043a88d7ea2d451c5384229d18356e46931 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 0bcaf5a00e58470760f724da243dfaa77084b545..1f642c249ba4da429b1913bdc0ca88a47e751436 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 f1062a0ec5d763ec84d653365e752d1b5b19b67f..513030986cd9914d1dca0a1796131b7bc55354a2 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 3d5c538c5b094b2ae768e0e6633da5df9ba95585..befab47166a8034d3a8a88fd6c5a35c88ccf9912 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 b276fe9aa51519cbfe5ec424f4ce67ef680752a1..928eda223b7adfcd6ae9bfb656a05a20ee842361 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 6db7c632fedc200018af67399dd071be2a4879e8..5735d935e09d2a1e05d91cbf8bcf39f2dcb64f34 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 5ced97eb1afd3be9fe54d61d063a372b91b8976c..009aa910d66b130fedf2b46ff6413804754ab6a7 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 406fbb99f60c761b1c7e87482568925a5f1f02c4..6f84c5308c024719f65c419fa4a80a3cb81c2274 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 ece0c3c56ede65b95e72636c563b367ed5389e78..4d55e892ada6c0d87cf20728444103617923c7a4 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 fd338fa1e12500aba6d97679c189ae0ed32656c1..0eb302565442583e93050eb7d50818d5622f9018 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 44957256ae61462bd598152d20742cd040825cd5..ac3e7fcefed7521e07be807a89a671e1c84b3509 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 e22d8f8c452064f67f3ecbc642b984941028a0fb..d8576a7e31cdd5d19330386f317bf80e4c6d487e 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 f392dbee7da5b15d26761d3f0cd73fc4a4356df1..1f8623a09b7443c6834457d8f4cf365739e5471b 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 567bdcfc441b1c30485574da94006f246f379825..be5a7a9470580f4e11654511ad44b865570ff561 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 502a4e68da3c0243b3999430ddad76cc38dd426a..4a42b6f78ff5eb5a2f2b51e87dc0e443d59bc01a 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 c1fb23c6d34e060f4926ec804f97e24955076ab4..306c44a768e66ef111fae61e51151077f057b31d 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 cfa34d6f1f9c1e8793e59c7666afcb6ff36827d1..52fba35ebf0768839354b4c96258f87da5cb8038 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 e22463c80eb169ebfbd4ffd332b2f22c06048ece..ae73cc91810923bf3f6636c7e6fd5108a0c97657 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 179ed072d8a4a67ba5939a5cdaabfd4c5743f054..641f9b82ab5cec2b8dbd6cfa42e83b2c29aa1c89 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 eab2c685386796d744afe6263b0bed42c9d1219e..28a507e839657216e303641d2a7f8fff0ee69045 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 7a44b43322c360b9d318a6b746d65aab1d7eb19e..01790f6a1515994e665726b7570625391c7f7ddd 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 21c9b2f3fda5f59b0ee322f04dc6af0877309ad6..9591878cdafebafeebce7d81cc7de35ad14405bc 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 6e681d746fcda44384aed22bc9b09ea867b3235a..61e4382fda398a1be458de2c603a2c8e77c35425 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 25b22709af141e107dc85385146c3bd3f6e48779..1042a3161fc7fd9b0672b941816b9ed901d69538 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 b9f84f891a64b6c2e4ae1fff57d70caa455b13fb..641180d4901d7df12f64d82db53599ec40f4ec53 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 8f1822dd5a0a6fcee40e60ebd3112371051799f8..bbf9ce444d24b5e63e910d5a7f8fc5d50b5875ac 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 a83205938b09f6605552103c65b535662c1456c4..50458504678b699aae0539eefaa343cf285c8543 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 63351b9dad6fa5947cfec402d0ecf43aaba38796..35dcd6bf934210257d6840733ef6615c4c6aeea1 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 de314fee1eb16a7e9b318476d126db0fc6b0e39d..6f2958b57ae38bf4d74bffe75c855f30586fca59 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 7c1636e5ac563eda2fdc12c13fe00d5817532bff..0a1568fc4442f8feb563f0571417ac4fe06f776e 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 8bb0df805780544168bd57cd6c6ce6c8d75e27b9..7179d35012989c8459f90fc8d162ba4b051f675d 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 e37a6b7ab025132d99e66af618ff51054b2cda51..fb7614b9e217a0ca038b92cf2bfd4356ecfe427d 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 3101a28c0c8a2a61cf9f96dc5418a7c565dc4551..bd7ae3e7e500a6416a5094271d6ba448dbaa6309 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 d5614645fdc4d3dfe79131f8a965c8f849297fab..d1221ebd066e5cd03b374df6451e6b49114f02b4 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 d13c9307f5c4303beae206e495875ccc23a99a02..07e4b531e913b147e4f5ffe12f6274e3d126afab 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 929db351d65c1a33f997e94f4ef37593bf6012c2..f07beca0d6f5f5e75d1e4fdf564bb247cb5c0f65 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 3bc1547081386fa3e75247d2b930b93041f11a6e..37e919c9a4d63a34c0be6da79718da95ac6572ed 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 bd33e5a87475d3fb712fa3ad78c6865defdea9bf..37305199b7295c501cbf7cc1cd472eee84f33128 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 654db164f2e7686efdcd26f99cadd1df3076c0d9..de9604768fb79d277adf1b04fa0a7bc942e2e63f 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 57a9ec4f809cd2d43dec480044fe4e27a14cc334..785fb56cc825cc6946e68aab329fcff8cb17d036 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 04a66f624917be8026a47e226b21ae12a00cb053..abfe688f17cdaaa3e53fcbea29d83f78a47a4e7f 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 1514db075fcc617ee06feac71edb62a7c92aba05..920b3449577bf7af2ee3379ed7758bdcf521b7d0 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 4231d4d4eac58d6420807530af882cc37bb06f35..f0316a958649b162a03bec0a55fc3b98107278b9 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 b9cbc894c8bfaea6cbeff4d1751ea9ff31bb3583..b98932fbc8e393307baa49d1de0ac8175fcfe99c 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 d35cd8bbac8c9566808426b8e61ec1a995f9ecc4..2607b91f20331c44f9e702050be04752a7f6ae1a 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 0b49bfe6e27aed78844bfe1667efd671dd84c278..82d1b5aa5c7c5084cffdcd549b9ea8240e4df0b4 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 67d825c6bcbe6c5235b32b1f2ae9cccc7998af9d..23cad41063c6e09963d76eca33c01f36ca745179 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 ba4ca97bc4bd8e5c97f1a8869d7e524e1ae7948d..e6fc999b37c2de8b75cfbdac2a83728102febec8 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 87a826bf2ce79bedd6fd047a804d739d15a2402f..75d122f9b4da2edc85678b60e94f90adfa970a95 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 1be56bbee9eb5da1e0f07166c9d9d73147565dee..e55af79c5f447f73c57ef83510e84982be9ce885 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 bda945b0690ca4a911672a728dbac2682d1cff4d..57c0ab40ab3fdb36c901f430cd2a9e3e10680505 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 f59b0dfda32afb4d9c1d7dbd617d768ca41fba03..353900b2b5366c7a7d7a617619229be9a8e2f518 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 7a203ad59766de6731a6ab573548a1f524e8d7fb..f312bcf338747eef509f6c8e621c0a818b110e53 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 c4bf9f7459dcf83d87f88e4818bec1ed3e623884..122e39013cb6e7252a9f69dcf3a4da70cb38f575 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 8a2d1b9864c0d52fef48ce14128d78ab429fad77..7f85ef9d97ef49c1f6c287960f42efb7f45fab56 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 c4e5b1b90727de198a2761c0fec30c4118289afe..638391a65c800000e73cf2e9d8b9285556dab43e 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 3347a012a5f5ef474671fc13eaaae0cf08261157..c54633c279d6d87c59c56b841a854ce161b87041 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 d28004738610c6fa8aacfb476fff0dc9bf81d2b0..b5d5b999abf319f201fd98f9e49bcab86ec42c59 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 d51bd95f5a420374eb7cbe8706c431646227311b..04771a8556f43ee0b1bd45b93de4de07614b1989 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 8750cc695bd261122bb49b98475065d389065858..8916c5eb100cecb21d68a60c27a42d6ffd340162 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 b9354cc2b266dcf4a423928bffbe4d38c7df4544..9e4ecd0b79438284c003be320f681de2c939712c 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 a12cedf8221931c48cf4dbff43daf0fadac81fdb..841c6d42e7e61d9791a1d87d39b929e9c09ae366 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 0683aaa4a274e1d1aafa9e98759a1aaaf8b85f8a..735421154444c63f7a9889a14c75855e1cc7f460 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 e57beef85f049cfd146fac61a7e2fd75209ecaeb..d6697936ffece84d6898fd1ed938a4b407184080 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 b7cb16fb7074dba58e6a81184aa4510aa248d387..7df9cdecca9cd2ded344d09e574b20c6ec77ffad 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 2c815ab22fa47bc9048d39de6f563aa14c2acaaa..796cae3b8a40efc885612609b92d0373cae1e97a 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 8f98a8e038197eff6a605de94a3c8723d3eff41d..6ec609bee0a7fa85e576f08d05d9943e802af829 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 38c6848b304569cc389678019833945f8fdcd5dd..a1b0296ba3969bc953395956221a8aab052d70ff 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