Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
CSDN 技术社区
skill_tree_mysql
提交
ff78e9ab
S
skill_tree_mysql
项目概览
CSDN 技术社区
/
skill_tree_mysql
通知
21
Star
0
Fork
1
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
skill_tree_mysql
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
ff78e9ab
编写于
6月 27, 2022
作者:
张
张志晨
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix bug
上级
fab1565d
变更
88
隐藏空白更改
内联
并排
Showing
88 changed file
with
476 addition
and
465 deletion
+476
-465
data/1.MySQL初阶/2.安装和登录/2.登录/prepare.md
data/1.MySQL初阶/2.安装和登录/2.登录/prepare.md
+5
-5
data/1.MySQL初阶/3.使用数据库/1. 创建和删除数据库/create_database.md
data/1.MySQL初阶/3.使用数据库/1. 创建和删除数据库/create_database.md
+7
-7
data/1.MySQL初阶/3.使用数据库/2.创建和删除表/auto_increment.md
data/1.MySQL初阶/3.使用数据库/2.创建和删除表/auto_increment.md
+5
-5
data/1.MySQL初阶/3.使用数据库/2.创建和删除表/create_table.md
data/1.MySQL初阶/3.使用数据库/2.创建和删除表/create_table.md
+6
-6
data/1.MySQL初阶/3.使用数据库/2.创建和删除表/drop_table.md
data/1.MySQL初阶/3.使用数据库/2.创建和删除表/drop_table.md
+6
-6
data/1.MySQL初阶/3.使用数据库/4.存储引擎/engine.md
data/1.MySQL初阶/3.使用数据库/4.存储引擎/engine.md
+5
-5
data/1.MySQL初阶/4.数据类型/1.数值类型/numbers.md
data/1.MySQL初阶/4.数据类型/1.数值类型/numbers.md
+2
-2
data/1.MySQL初阶/4.数据类型/2.日期和时间类型/datetime.md
data/1.MySQL初阶/4.数据类型/2.日期和时间类型/datetime.md
+6
-6
data/1.MySQL初阶/4.数据类型/3.文本字符串类型/description.md
data/1.MySQL初阶/4.数据类型/3.文本字符串类型/description.md
+6
-6
data/1.MySQL初阶/4.数据类型/4.二进制字符串类型/binary.md
data/1.MySQL初阶/4.数据类型/4.二进制字符串类型/binary.md
+6
-6
data/1.MySQL初阶/5.数据修改/1.插入/insert.md
data/1.MySQL初阶/5.数据修改/1.插入/insert.md
+6
-6
data/1.MySQL初阶/5.数据修改/2.修改/update.md
data/1.MySQL初阶/5.数据修改/2.修改/update.md
+5
-5
data/1.MySQL初阶/5.数据修改/3.删除/delete.md
data/1.MySQL初阶/5.数据修改/3.删除/delete.md
+7
-7
data/1.MySQL初阶/6.数据查询/1.SELECT/select.md
data/1.MySQL初阶/6.数据查询/1.SELECT/select.md
+6
-6
data/1.MySQL初阶/6.数据查询/2.WHERE/where.md
data/1.MySQL初阶/6.数据查询/2.WHERE/where.md
+6
-6
data/1.MySQL初阶/6.数据查询/3.运算符/geo.md
data/1.MySQL初阶/6.数据查询/3.运算符/geo.md
+7
-6
data/2.MySQL中阶/1.数据库组成/1.表/create_table.md
data/2.MySQL中阶/1.数据库组成/1.表/create_table.md
+4
-4
data/2.MySQL中阶/1.数据库组成/2.视图/view.md
data/2.MySQL中阶/1.数据库组成/2.视图/view.md
+6
-6
data/2.MySQL中阶/1.数据库组成/3.存储过程和函数/create_function.md
data/2.MySQL中阶/1.数据库组成/3.存储过程和函数/create_function.md
+4
-4
data/2.MySQL中阶/1.数据库组成/3.存储过程和函数/create_procedure.md
data/2.MySQL中阶/1.数据库组成/3.存储过程和函数/create_procedure.md
+5
-5
data/2.MySQL中阶/1.数据库组成/3.存储过程和函数/drop_function.md
data/2.MySQL中阶/1.数据库组成/3.存储过程和函数/drop_function.md
+4
-4
data/2.MySQL中阶/1.数据库组成/4.索引和约束/unique.md
data/2.MySQL中阶/1.数据库组成/4.索引和约束/unique.md
+1
-1
data/2.MySQL中阶/1.数据库组成/4.索引和约束/unique_2.md
data/2.MySQL中阶/1.数据库组成/4.索引和约束/unique_2.md
+1
-1
data/2.MySQL中阶/1.数据库组成/5. 触发器/audit.md
data/2.MySQL中阶/1.数据库组成/5. 触发器/audit.md
+7
-7
data/2.MySQL中阶/1.数据库组成/5. 触发器/trigger.md
data/2.MySQL中阶/1.数据库组成/5. 触发器/trigger.md
+1
-1
data/2.MySQL中阶/1.数据库组成/6.存储引擎/upgrade_engine.md
data/2.MySQL中阶/1.数据库组成/6.存储引擎/upgrade_engine.md
+3
-3
data/2.MySQL中阶/10.用户和权限/1.创建普通用户/create_user.md
data/2.MySQL中阶/10.用户和权限/1.创建普通用户/create_user.md
+5
-4
data/2.MySQL中阶/10.用户和权限/2.为用户授权/grant.md
data/2.MySQL中阶/10.用户和权限/2.为用户授权/grant.md
+6
-6
data/2.MySQL中阶/10.用户和权限/2.为用户授权/role.md
data/2.MySQL中阶/10.用户和权限/2.为用户授权/role.md
+4
-4
data/2.MySQL中阶/10.用户和权限/3.查看用户权限/view_privileges.md
data/2.MySQL中阶/10.用户和权限/3.查看用户权限/view_privileges.md
+4
-4
data/2.MySQL中阶/10.用户和权限/4.撤销用户权限/revoke.md
data/2.MySQL中阶/10.用户和权限/4.撤销用户权限/revoke.md
+4
-4
data/2.MySQL中阶/10.用户和权限/5.修改用户密码/change_password.md
data/2.MySQL中阶/10.用户和权限/5.修改用户密码/change_password.md
+5
-4
data/2.MySQL中阶/10.用户和权限/6.删除用户/drop_user.md
data/2.MySQL中阶/10.用户和权限/6.删除用户/drop_user.md
+5
-4
data/2.MySQL中阶/10.用户和权限/7.限制用户使用资源/limit_action.md
data/2.MySQL中阶/10.用户和权限/7.限制用户使用资源/limit_action.md
+5
-5
data/2.MySQL中阶/2.查询进阶/2. BETWEEN/between.md
data/2.MySQL中阶/2.查询进阶/2. BETWEEN/between.md
+5
-5
data/2.MySQL中阶/2.查询进阶/3.CASE/case.md
data/2.MySQL中阶/2.查询进阶/3.CASE/case.md
+6
-6
data/2.MySQL中阶/2.查询进阶/4.DISTINCT/distinct.md
data/2.MySQL中阶/2.查询进阶/4.DISTINCT/distinct.md
+6
-6
data/2.MySQL中阶/2.查询进阶/5.ORDER BY/order_by.md
data/2.MySQL中阶/2.查询进阶/5.ORDER BY/order_by.md
+7
-7
data/2.MySQL中阶/2.查询进阶/6.UNION/union.md
data/2.MySQL中阶/2.查询进阶/6.UNION/union.md
+7
-7
data/2.MySQL中阶/2.查询进阶/7.正则表达式/regex.md
data/2.MySQL中阶/2.查询进阶/7.正则表达式/regex.md
+4
-4
data/2.MySQL中阶/2.查询进阶/8. 分页查询/paged.md
data/2.MySQL中阶/2.查询进阶/8. 分页查询/paged.md
+5
-5
data/2.MySQL中阶/3.内置函数/5.其它函数/cast.md
data/2.MySQL中阶/3.内置函数/5.其它函数/cast.md
+2
-2
data/2.MySQL中阶/3.内置函数/5.其它函数/convert.md
data/2.MySQL中阶/3.内置函数/5.其它函数/convert.md
+6
-6
data/2.MySQL中阶/4.聚合和分组/1. 计数/count.md
data/2.MySQL中阶/4.聚合和分组/1. 计数/count.md
+1
-1
data/2.MySQL中阶/4.聚合和分组/2. 求和/sum.md
data/2.MySQL中阶/4.聚合和分组/2. 求和/sum.md
+7
-6
data/2.MySQL中阶/4.聚合和分组/3.最小值/min.md
data/2.MySQL中阶/4.聚合和分组/3.最小值/min.md
+7
-6
data/2.MySQL中阶/4.聚合和分组/4. 最大值/max.md
data/2.MySQL中阶/4.聚合和分组/4. 最大值/max.md
+6
-6
data/2.MySQL中阶/4.聚合和分组/5. 平均值/avg.md
data/2.MySQL中阶/4.聚合和分组/5. 平均值/avg.md
+7
-6
data/2.MySQL中阶/4.聚合和分组/6.HAVING/having.md
data/2.MySQL中阶/4.聚合和分组/6.HAVING/having.md
+6
-6
data/2.MySQL中阶/5.子查询/1.相关子查询/subquery.md
data/2.MySQL中阶/5.子查询/1.相关子查询/subquery.md
+5
-5
data/2.MySQL中阶/5.子查询/2. ANY/any.md
data/2.MySQL中阶/5.子查询/2. ANY/any.md
+5
-5
data/2.MySQL中阶/5.子查询/3.ALL/all.md
data/2.MySQL中阶/5.子查询/3.ALL/all.md
+6
-6
data/2.MySQL中阶/5.子查询/4.EXISTS/exists.md
data/2.MySQL中阶/5.子查询/4.EXISTS/exists.md
+6
-6
data/2.MySQL中阶/5.子查询/5. IN/in.md
data/2.MySQL中阶/5.子查询/5. IN/in.md
+6
-6
data/2.MySQL中阶/5.子查询/6. 列子查询/in_column.md
data/2.MySQL中阶/5.子查询/6. 列子查询/in_column.md
+5
-5
data/2.MySQL中阶/6.连接查询/1.INNER JOIN/join_self.md
data/2.MySQL中阶/6.连接查询/1.INNER JOIN/join_self.md
+6
-6
data/2.MySQL中阶/6.连接查询/2. LEFT JOIN/left_join.md
data/2.MySQL中阶/6.连接查询/2. LEFT JOIN/left_join.md
+7
-7
data/2.MySQL中阶/6.连接查询/3. RIGHT JOIN/right_join.md
data/2.MySQL中阶/6.连接查询/3. RIGHT JOIN/right_join.md
+7
-7
data/2.MySQL中阶/6.连接查询/4. CROSS JOIN/cross_join.md
data/2.MySQL中阶/6.连接查询/4. CROSS JOIN/cross_join.md
+8
-8
data/2.MySQL中阶/6.连接查询/5. 复杂连接/salary.md
data/2.MySQL中阶/6.连接查询/5. 复杂连接/salary.md
+6
-6
data/2.MySQL中阶/7. 索引/2.创建索引/create_index.md
data/2.MySQL中阶/7. 索引/2.创建索引/create_index.md
+6
-5
data/2.MySQL中阶/7. 索引/3.删除索引/drop_index.md
data/2.MySQL中阶/7. 索引/3.删除索引/drop_index.md
+8
-8
data/3.MySQL高阶/1.深入索引/1.唯一索引/unique.md
data/3.MySQL高阶/1.深入索引/1.唯一索引/unique.md
+5
-5
data/3.MySQL高阶/1.深入索引/2.全值匹配/total_index.md
data/3.MySQL高阶/1.深入索引/2.全值匹配/total_index.md
+5
-4
data/3.MySQL高阶/1.深入索引/3.匹配顺序/match_fields.md
data/3.MySQL高阶/1.深入索引/3.匹配顺序/match_fields.md
+5
-5
data/3.MySQL高阶/1.深入索引/4.组合索引/combinate.md
data/3.MySQL高阶/1.深入索引/4.组合索引/combinate.md
+5
-5
data/3.MySQL高阶/1.深入索引/5.空间索引/geo_index.md
data/3.MySQL高阶/1.深入索引/5.空间索引/geo_index.md
+6
-6
data/3.MySQL高阶/1.深入索引/6.全文索引/full_text_index.md
data/3.MySQL高阶/1.深入索引/6.全文索引/full_text_index.md
+6
-5
data/3.MySQL高阶/1.深入索引/7.隐藏索引/invisible.md
data/3.MySQL高阶/1.深入索引/7.隐藏索引/invisible.md
+6
-6
data/3.MySQL高阶/1.深入索引/8.函数和表达式索引/daily_payment.md
data/3.MySQL高阶/1.深入索引/8.函数和表达式索引/daily_payment.md
+7
-7
data/3.MySQL高阶/2.SQL高级技巧/1.CTE和递归查询/continuous.md
data/3.MySQL高阶/2.SQL高级技巧/1.CTE和递归查询/continuous.md
+5
-5
data/3.MySQL高阶/2.SQL高级技巧/1.CTE和递归查询/to_root.md
data/3.MySQL高阶/2.SQL高级技巧/1.CTE和递归查询/to_root.md
+5
-5
data/3.MySQL高阶/2.SQL高级技巧/2.Window Function/salary.md
data/3.MySQL高阶/2.SQL高级技巧/2.Window Function/salary.md
+7
-7
data/3.MySQL高阶/2.SQL高级技巧/3.透视表 /pivot.md
data/3.MySQL高阶/2.SQL高级技巧/3.透视表 /pivot.md
+5
-5
data/3.MySQL高阶/2.SQL高级技巧/4.Double Not Exists/DoubleNotExists.md
....MySQL高阶/2.SQL高级技巧/4.Double Not Exists/DoubleNotExists.md
+6
-6
data/3.MySQL高阶/2.SQL高级技巧/5.写入和冲突/score.md
data/3.MySQL高阶/2.SQL高级技巧/5.写入和冲突/score.md
+6
-6
data/3.MySQL高阶/2.SQL高级技巧/6.事务/transaction.md
data/3.MySQL高阶/2.SQL高级技巧/6.事务/transaction.md
+2
-2
data/3.MySQL高阶/3. 过程化编程/1.IF/if.md
data/3.MySQL高阶/3. 过程化编程/1.IF/if.md
+5
-5
data/3.MySQL高阶/3. 过程化编程/2.LOOP/loop.md
data/3.MySQL高阶/3. 过程化编程/2.LOOP/loop.md
+5
-5
data/3.MySQL高阶/3. 过程化编程/3.REPEAT/repeat.md
data/3.MySQL高阶/3. 过程化编程/3.REPEAT/repeat.md
+6
-6
data/3.MySQL高阶/3. 过程化编程/4.WHILE/while.md
data/3.MySQL高阶/3. 过程化编程/4.WHILE/while.md
+6
-6
data/3.MySQL高阶/3. 过程化编程/5. 游标/cursor.md
data/3.MySQL高阶/3. 过程化编程/5. 游标/cursor.md
+7
-7
data/3.MySQL高阶/4.设计优化/1.生成列/generated.md
data/3.MySQL高阶/4.设计优化/1.生成列/generated.md
+5
-5
data/3.MySQL高阶/4.设计优化/2. 范式设计/customer_order.md
data/3.MySQL高阶/4.设计优化/2. 范式设计/customer_order.md
+1
-1
data/3.MySQL高阶/4.设计优化/4.增加中间表/daily_payment2.md
data/3.MySQL高阶/4.设计优化/4.增加中间表/daily_payment2.md
+10
-10
data/3.MySQL高阶/5.运维与架构/6.复制过滤器/filter.md
data/3.MySQL高阶/5.运维与架构/6.复制过滤器/filter.md
+14
-13
data/3.MySQL高阶/6.查询优化/1. SHOW STATUS/show_status.md
data/3.MySQL高阶/6.查询优化/1. SHOW STATUS/show_status.md
+4
-4
data/3.MySQL高阶/6.查询优化/3. EXPLAIN/explain.md
data/3.MySQL高阶/6.查询优化/3. EXPLAIN/explain.md
+4
-4
未找到文件。
data/1.MySQL初阶/2.安装和登录/2.登录/prepare.md
浏览文件 @
ff78e9ab
...
...
@@ -24,7 +24,7 @@ sudo su
mysql mysql
```
创建数据库用户 joe 并授权:
```
my
sql
```
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 授权
```
my
sql
```
sql
grant
all
privileges
on
*
.
*
to
joe
;
flush
privileges
;
```
...
...
@@ -54,7 +54,7 @@ mysql mysql
```
为 joe 授权
```
my
sql
```
sql
grant
all
privileges
on
*
.
*
to
joe
;
flush
privileges
;
```
...
...
@@ -67,7 +67,7 @@ mysql mysql
```
创建数据库用户 joe
```
my
sql
```
sql
create
user
'joe'
@
'localhost'
identified
by
'joe'
;
flush
privileges
;
```
...
...
@@ -80,7 +80,7 @@ sudo su
mysql mysql
```
创建数据库用户 joe 并授权:
```
my
sql
```
sql
create
user
'joe'
@
'%'
identified
by
'joe'
;
grant
all
privileges
on
*
.
*
to
joe
;
flush
privileges
;
...
...
data/1.MySQL初阶/3.使用数据库/1. 创建和删除数据库/create_database.md
浏览文件 @
ff78e9ab
...
...
@@ -11,7 +11,7 @@ Joe 在开发机上创建了一个名为 goods 的数据库,做了一些练习
## 答案
```
my
sql
```
sql
drop
database
goods
;
create
database
goods
;
```
...
...
@@ -20,14 +20,14 @@ create database goods;
### A
```
my
sql
```
sql
delete
database
goods
;
create
database
goods
;
```
### B
```
my
sql
```
sql
if
exists
(
database
goods
)
then
begin
drop
database
goods
;
...
...
@@ -37,7 +37,7 @@ create database goods;
### C
```
my
sql
```
sql
use
goods
;
drop
database
goods
;
create
database
goods
;
...
...
@@ -45,7 +45,7 @@ create database goods;
### D
```
my
sql
```
sql
use
goods
;
drop
database
goods
;
make
database
goods
;
...
...
@@ -53,14 +53,14 @@ make database goods;
### E
```
my
sql
```
sql
drop
database
goods
;
make
database
goods
;
```
### F
```
my
sql
```
sql
cd
goods
;
drop
database
goods
;
create
database
goods
;
...
...
data/1.MySQL初阶/3.使用数据库/2.创建和删除表/auto_increment.md
浏览文件 @
ff78e9ab
...
...
@@ -11,7 +11,7 @@ Joe 需要重建一个 id 为自增字段的 goods_category 。他已经删除
## 答案
```
my
sql
```
sql
CREATE
TABLE
goods_category
(
id
INT
PRIMARY
KEY
AUTO_INCREMENT
,
...
...
@@ -24,7 +24,7 @@ CREATE TABLE goods_category
### A
```
my
sql
```
sql
CREATE
TABLE
goods_category
(
id
INT
PRIMARY
KEY
SERIALS
,
...
...
@@ -35,7 +35,7 @@ CREATE TABLE goods_category
### B
```
my
sql
```
sql
CREATE
TABLE
goods_category
(
id
INT
,
...
...
@@ -48,7 +48,7 @@ CREATE TABLE goods_category
### C
```
my
sql
```
sql
CREATE
TABLE
goods_category
(
id
INT
PRIMARY
KEY
,
...
...
@@ -59,7 +59,7 @@ CREATE TABLE goods_category
### D
```
my
sql
```
sql
CREATE
TABLE
goods_category
(
id
INT
PRIMARY
KEY
SERIALS
,
...
...
data/1.MySQL初阶/3.使用数据库/2.创建和删除表/create_table.md
浏览文件 @
ff78e9ab
...
...
@@ -11,7 +11,7 @@ Joe 想要在 goods 数据库创建一个 goods_category 表,管理商品的
## 答案
```
my
sql
```
sql
CREATE
TABLE
goods_category
(
id
INT
PRIMARY
KEY
,
...
...
@@ -24,7 +24,7 @@ CREATE TABLE goods_category
### A
```
my
sql
```
sql
MAKE
TABLE
goods_category
(
id
INT
PRIMARY
KEY
,
...
...
@@ -35,7 +35,7 @@ MAKE TABLE goods_category
### B
```
my
sql
```
sql
DROP
TABLE
goods_category
(
id
INT
PRIMARY
KEY
,
...
...
@@ -46,7 +46,7 @@ DROP TABLE goods_category
### C
```
my
sql
```
sql
SAVE
TABLE
goods_category
(
id
INT
PRIMARY
KEY
,
...
...
@@ -57,7 +57,7 @@ SAVE TABLE goods_category
### D
```
my
sql
```
sql
ADD
TABLE
goods_category
(
id
INT
PRIMARY
KEY
,
...
...
@@ -68,7 +68,7 @@ ADD TABLE goods_category
### E
```
my
sql
```
sql
PUT
TABLE
goods_category
(
id
INT
PRIMARY
KEY
,
...
...
data/1.MySQL初阶/3.使用数据库/2.创建和删除表/drop_table.md
浏览文件 @
ff78e9ab
...
...
@@ -11,7 +11,7 @@ Joe 想要删除数据库中的 good_category 表,他应该怎么操作?
## 答案
```
my
sql
```
sql
drop
table
goods_category
;
```
...
...
@@ -19,30 +19,30 @@ drop table goods_category;
### A
```
my
sql
```
sql
delete
table
good_category
;
```
### B
```
my
sql
```
sql
delete
table
where
name
=
'good_category'
;
```
### C
```
my
sql
```
sql
remove
table
good_category
;
```
### D
```
my
sql
```
sql
truncate
table
goods_category
;
```
### E
```
my
sql
```
sql
clean
table
goods_category
;
```
data/1.MySQL初阶/3.使用数据库/4.存储引擎/engine.md
浏览文件 @
ff78e9ab
...
...
@@ -11,7 +11,7 @@ Joe 需要确保 goods_category 表的存储引擎为 innodb ,那么建表语
## 答案
```
my
sql
```
sql
CREATE
TABLE
goods_category
(
id
INT
,
...
...
@@ -24,7 +24,7 @@ CREATE TABLE goods_category
### A
```
my
sql
```
sql
CREATE
TABLE
goods_category
(
id
INT
,
...
...
@@ -35,7 +35,7 @@ CREATE TABLE goods_category
### B
```
my
sql
```
sql
WITH
ENGINE
=
INNODB
CREATE
TABLE
goods_category
(
id
INT
,
...
...
@@ -46,7 +46,7 @@ WITH ENGINE=INNODB CREATE TABLE goods_category
### C
```
my
sql
```
sql
SAVE
TABLE
goods_category
(
id
INT
,
...
...
@@ -57,7 +57,7 @@ SAVE TABLE goods_category
### D
```
my
sql
```
sql
CREATE
TABLE
goods_category
(
id
INT
,
...
...
data/1.MySQL初阶/4.数据类型/1.数值类型/numbers.md
浏览文件 @
ff78e9ab
...
...
@@ -9,7 +9,7 @@ Joe 需要使用下列表做一项数值计算
*
`show databases;`
列出所有数据库
*
`show tables;`
列出所有表
```
my
sql
```
sql
create
table
points
(
id
int
primary
key
auto_increment
,
x
int
,
...
...
@@ -19,7 +19,7 @@ create table points(
计算查询为:
```
my
sql
```
sql
select
id
,
(
x
^
2
+
y
^
2
)
/
2
as
result
from
points
;
```
...
...
data/1.MySQL初阶/4.数据类型/2.日期和时间类型/datetime.md
浏览文件 @
ff78e9ab
...
...
@@ -2,7 +2,7 @@
Joe 写了一个订单表的创建语句:
```
my
sql
```
sql
create
table
orders
(
id
int
primary
key
auto_increment
,
item_id
int
,
...
...
@@ -23,7 +23,7 @@ create table orders (
## 答案
```
my
sql
```
sql
create
table
orders
(
id
int
primary
key
auto_increment
,
item_id
int
,
...
...
@@ -38,7 +38,7 @@ create table orders (
### A
```
my
sql
```
sql
create
table
orders
(
id
int
primary
key
auto_increment
,
item_id
int
,
...
...
@@ -51,7 +51,7 @@ create table orders (
### B
```
my
sql
```
sql
create
table
orders
(
id
int
primary
key
auto_increment
,
item_id
int
,
...
...
@@ -64,7 +64,7 @@ create table orders (
### C
```
my
sql
```
sql
create
table
orders
(
id
int
primary
key
auto_increment
,
item_id
int
,
...
...
@@ -77,7 +77,7 @@ create table orders (
### D
```
my
sql
```
sql
create
table
orders
(
id
int
primary
key
auto_increment
,
item_id
int
,
...
...
data/1.MySQL初阶/4.数据类型/3.文本字符串类型/description.md
浏览文件 @
ff78e9ab
...
...
@@ -2,7 +2,7 @@
Joe 在设计订单表,他已经完成了下列内容:
```
my
sql
```
sql
create
table
orders
(
id
int
primary
key
auto_increment
,
item_id
int
,
...
...
@@ -24,7 +24,7 @@ create table orders (
## 答案
```
my
sql
```
sql
create
table
orders
(
id
int
primary
key
auto_increment
,
item_id
int
,
...
...
@@ -40,7 +40,7 @@ create table orders (
### A
```
my
sql
```
sql
create
table
orders
(
id
int
primary
key
auto_increment
,
item_id
int
,
...
...
@@ -54,7 +54,7 @@ create table orders (
### B
```
my
sql
```
sql
create
table
orders
(
id
int
primary
key
auto_increment
,
item_id
int
,
...
...
@@ -68,7 +68,7 @@ create table orders (
### C
```
my
sql
```
sql
create
table
orders
(
id
int
primary
key
auto_increment
,
item_id
int
,
...
...
@@ -82,7 +82,7 @@ create table orders (
### D
```
my
sql
```
sql
create
table
orders
(
id
int
primary
key
auto_increment
,
item_id
int
,
...
...
data/1.MySQL初阶/4.数据类型/4.二进制字符串类型/binary.md
浏览文件 @
ff78e9ab
...
...
@@ -2,7 +2,7 @@
现在 Joe 的订单表已经有了如下形态:
```
my
sql
```
sql
create
table
orders
(
id
int
primary
key
auto_increment
,
item_id
int
,
...
...
@@ -25,7 +25,7 @@ create table orders (
## 答案
```
my
sql
```
sql
create
table
orders
(
id
int
primary
key
auto_increment
,
item_id
int
,
...
...
@@ -42,7 +42,7 @@ create table orders (
### A
```
my
sql
```
sql
create
table
orders
(
id
int
primary
key
auto_increment
,
item_id
int
,
...
...
@@ -57,7 +57,7 @@ create table orders (
### B
```
my
sql
```
sql
create
table
orders
(
id
int
primary
key
auto_increment
,
item_id
int
,
...
...
@@ -72,7 +72,7 @@ create table orders (
### C
```
my
sql
```
sql
create
table
orders
(
id
int
primary
key
auto_increment
,
item_id
int
,
...
...
@@ -87,7 +87,7 @@ create table orders (
### D
```
my
sql
```
sql
create
table
orders
(
id
int
primary
key
auto_increment
,
item_id
int
,
...
...
data/1.MySQL初阶/5.数据修改/1.插入/insert.md
浏览文件 @
ff78e9ab
...
...
@@ -2,7 +2,7 @@
Goods 数据库中有一个表:
```
my
sql
```
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);
## 答案
```
my
sql
```
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
### 唯一键冲突
```
my
sql
```
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'
;
```
### 缺少必要的列
```
my
sql
```
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'
;
```
### 类型错误
```
my
sql
```
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'
;
```
### 违反非空约束
```
my
sql
```
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'
;
```
data/1.MySQL初阶/5.数据修改/2.修改/update.md
浏览文件 @
ff78e9ab
...
...
@@ -2,7 +2,7 @@
现有 employee 表如下:
```
my
sql
```
sql
create
table
employee
(
id
serial
primary
key
,
...
...
@@ -23,7 +23,7 @@ Joe 希望修改销售部(dept 字段为 sale)员工 Dora Muk 的工资,将其
## 答案
```
my
sql
```
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
### 过滤条件不严谨
```
my
sql
```
sql
update
employee
set
salary
=
salary
+
1000
where
name
=
'Dora Muk'
;
```
### 缺少过滤条件
```
my
sql
```
sql
update
employee
set
salary
=
salary
+
1000
;
```
### 错误的赋值语句
```
my
sql
```
sql
update
employee
set
salary
+=
1000
;
```
data/1.MySQL初阶/5.数据修改/3.删除/delete.md
浏览文件 @
ff78e9ab
...
...
@@ -2,7 +2,7 @@
现在 orders 表结构如下:
```
my
sql
```
sql
create
table
orders
(
id
int
primary
key
auto_increment
,
item_id
int
,
...
...
@@ -28,7 +28,7 @@ create table orders (
在一个独立的定时任务中执行
```
my
sql
```
sql
delete
from
orders
where
deal
;
...
...
@@ -40,7 +40,7 @@ where deal;
在一个独立的定时任务中执行
```
my
sql
```
sql
truncate
orders
;
```
...
...
@@ -48,7 +48,7 @@ truncate orders;
在一个独立的定时任务中执行
```
my
sql
```
sql
delete
from
orders
;
```
...
...
@@ -57,7 +57,7 @@ from orders;
在一个独立的定时任务中执行
```
my
sql
```
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 (
建立视图
```
my
sql
```
sql
create
view
order_view
as
select
id
,
meta
,
content
,
created_at
from
orders
...
...
@@ -88,7 +88,7 @@ where not deal;
在一个独立的定时任务中执行
```
my
sql
```
sql
delete
from
orders
where
deal
;
...
...
data/1.MySQL初阶/6.数据查询/1.SELECT/select.md
浏览文件 @
ff78e9ab
...
...
@@ -11,7 +11,7 @@
## 答案
```
my
sql
```
sql
from
test
select
abc
;
```
...
...
@@ -20,31 +20,31 @@ from test select abc;
### A
```
my
sql
```
sql
select
3
.
14
;
```
### B
```
my
sql
```
sql
select
*
from
employee
;
```
### C
```
my
sql
```
sql
select
*
from
employee
where
dept
=
'hr'
;
```
### D
```
my
sql
```
sql
select
id
,
name
,
dept
,
salary
from
employee
where
salary
>
10000
;
```
### E
```
my
sql
```
sql
select
now
();
```
data/1.MySQL初阶/6.数据查询/2.WHERE/where.md
浏览文件 @
ff78e9ab
...
...
@@ -2,7 +2,7 @@
Joe 希望从 orders 表
```
my
sql
```
sql
create
table
orders
(
id
int
primary
key
auto_increment
,
...
...
@@ -27,7 +27,7 @@ create table orders
## 答案
```
my
sql
```
sql
select
id
from
orders
where
date
(
ts
)
=
'2022-05-25'
...
...
@@ -38,7 +38,7 @@ where date(ts) = '2022-05-25'
### A
```
my
sql
```
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
```
my
sql
```
sql
select
id
from
orders
where
date
(
ts
)
=
'2022-05-25'
...
...
@@ -55,7 +55,7 @@ where date(ts) = '2022-05-25'
### C
```
my
sql
```
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
```
my
sql
```
sql
select
id
from
orders
which
date
(
ts
)
=
'2022-05-25'
...
...
data/1.MySQL初阶/6.数据查询/3.运算符/geo.md
浏览文件 @
ff78e9ab
...
...
@@ -2,7 +2,7 @@
Points 表结构如下:
```
my
sql
```
sql
create
table
points
(
id
int
primary
key
auto_increment
,
x
float
,
...
...
@@ -21,7 +21,7 @@ create table points(
## 答案
```
my
sql
```
sql
select
id
,
sqrt
(
x
^
2
+
y
^
2
)
from
points
;
```
...
...
@@ -29,24 +29,24 @@ select id, sqrt(x^2 + y^2) from points;
### A
```
my
sql
```
sql
select
sqrt
(
vx
+
vy
)
from
(
select
x
^
2
as
vx
,
y
^
2
as
vy
from
points
)
as
t
;
```
### B
```
my
sql
```
sql
select
sqrt
(
vx
+
vy
)
from
points
where
x
^
2
as
vx
,
y
^
2
as
vy
;
```
### C
```
my
sql
```
sql
select
id
+
sqrt
(
x
^
2
+
y
^
2
)
from
points
;
```
### D
```
my
sql
```
sql
select
id
||
sqrt
(
x
^
2
+
y
^
2
)
from
points
;
```
\ No newline at end of file
data/2.MySQL中阶/1.数据库组成/1.表/create_table.md
浏览文件 @
ff78e9ab
...
...
@@ -12,7 +12,7 @@
## 答案
```
my
sql
```
sql
create
table
trade
(
id
int
primary
key
auto_increment
,
content
varchar
(
8000
),
...
...
@@ -24,7 +24,7 @@ create table trade (
### 主键没有设置自增,不符合题意
```
my
sql
```
sql
create
table
trade
(
id
integer
primary
key
,
content
varchar
(
8000
),
...
...
@@ -34,7 +34,7 @@ create table trade (
### 时间戳没有设置默认值
```
my
sql
```
sql
create
table
trade
(
id
serial
primary
key
,
content
varchar
(
8000
),
...
...
@@ -44,7 +44,7 @@ create table trade (
### 没有主键,不符合题设
```
my
sql
```
sql
create
table
trade
(
id
serial
,
content
varchar
(
8000
),
...
...
data/2.MySQL中阶/1.数据库组成/2.视图/view.md
浏览文件 @
ff78e9ab
...
...
@@ -2,7 +2,7 @@
Joe 需要给 goods 表
```
my
sql
```
sql
create
table
goods
(
id
int
primary
key
auto_increment
,
category_id
int
,
...
...
@@ -25,7 +25,7 @@ create table goods(
## 答案
```
my
sql
```
sql
CREATE
VIEW
view_name_price
AS
SELECT
name
,
price
...
...
@@ -37,7 +37,7 @@ CREATE VIEW view_name_price
### A
```
my
sql
```
sql
CREATE
VIEW
view_name_price
AS
SELECT
name
,
price
...
...
@@ -46,7 +46,7 @@ CREATE VIEW view_name_price
### B
```
my
sql
```
sql
CREATE
VIEW
view_name_price
AS
SELECT
*
...
...
@@ -56,7 +56,7 @@ CREATE VIEW view_name_price
### C
```
my
sql
```
sql
CREATE
VIEW
view_name_price
AS
BEGIN
...
...
@@ -68,7 +68,7 @@ END;
### D
```
my
sql
```
sql
CREATE
VIEW
view_name_price
AS
BEGIN
...
...
data/2.MySQL中阶/1.数据库组成/3.存储过程和函数/create_function.md
浏览文件 @
ff78e9ab
...
...
@@ -12,7 +12,7 @@
## 答案
```
my
sql
```
sql
create
function
individual_income_tax
(
salary
decimal
(
12
,
4
))
returns
decimal
(
12
,
4
)
deterministic
begin
...
...
@@ -24,7 +24,7 @@ end;
### A
```
my
sql
```
sql
create
store
function
individual_income_tax
(
salary
decimal
(
12
,
4
))
returns
decimal
(
12
,
4
)
deterministic
begin
...
...
@@ -34,7 +34,7 @@ end;
### B
```
my
sql
```
sql
create
function
individual_income_tax
(
salary
decimal
(
12
,
4
))
deterministic
begin
...
...
@@ -45,7 +45,7 @@ end;
### C
```
my
sql
```
sql
create
function
decimal
(
12
,
4
)
individual_income_tax
(
salary
decimal
(
12
,
4
))
begin
-- ...
...
...
data/2.MySQL中阶/1.数据库组成/3.存储过程和函数/create_procedure.md
浏览文件 @
ff78e9ab
...
...
@@ -13,7 +13,7 @@ Joe 希望这个计算更紧凑一些,在已经有 individual_income_tax 的
## 答案
```
my
sql
```
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
```
my
sql
```
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
```
my
sql
```
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
```
my
sql
```
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
```
my
sql
```
sql
create
procedure
sp_idt
(
in
salary
decimal
(
12
,
4
))
begin
declare
tax
,
take_home
decimal
(
12
,
4
);
...
...
data/2.MySQL中阶/1.数据库组成/3.存储过程和函数/drop_function.md
浏览文件 @
ff78e9ab
...
...
@@ -11,7 +11,7 @@ Joe 将计税逻辑放到了 sp_idt 中,现在不需要 individual_income_tax
## 答案
```
my
sql
```
sql
drop
function
individual_income_tax
;
```
...
...
@@ -19,20 +19,20 @@ drop function individual_income_tax;
### A
```
my
sql
```
sql
delete
function
individual_income_tax
;
```
### B
```
my
sql
```
sql
remove
function
individual_income_tax
;
```
### C
```
my
sql
```
sql
drop
function
individual_income_tax
(
decimal
(
12
,
4
));
```
data/2.MySQL中阶/1.数据库组成/4.索引和约束/unique.md
浏览文件 @
ff78e9ab
...
...
@@ -2,7 +2,7 @@
现有一个图书登记表:
```
my
sql
```
sql
create
table
book
(
id
int
primary
key
auto_increment
,
title
text
,
...
...
data/2.MySQL中阶/1.数据库组成/4.索引和约束/unique_2.md
浏览文件 @
ff78e9ab
...
...
@@ -2,7 +2,7 @@
现有一个图书登记表:
```
my
sql
```
sql
create
table
book
(
id
int
primary
key
auto_increment
,
title
text
,
...
...
data/2.MySQL中阶/1.数据库组成/5. 触发器/audit.md
浏览文件 @
ff78e9ab
...
...
@@ -2,7 +2,7 @@
Orders 表
```
my
sql
```
sql
create
table
orders
(
id
int
primary
key
auto_increment
,
...
...
@@ -17,7 +17,7 @@ create table orders
记录了未完成的订单。审计部门现在需要记录其变更——新增或删除,该表不会发生update——即将修改都记录到 orders_log 表
```
my
sql
```
sql
create
table
orders_log
(
log_id
int
primary
key
auto_increment
,
...
...
@@ -44,7 +44,7 @@ create table orders_log
## 答案
```
my
sql
```
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
```
my
sql
```
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
```
my
sql
```
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
```
my
sql
```
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
```
my
sql
```
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'
);
...
...
data/2.MySQL中阶/1.数据库组成/5. 触发器/trigger.md
浏览文件 @
ff78e9ab
...
...
@@ -2,7 +2,7 @@
SmartMarket 公司的OA数据库中包含以下结构:
```
my
sql
```
sql
create
table
employee
(
id
serial
primary
key
,
name
varchar
(
256
),
...
...
data/2.MySQL中阶/1.数据库组成/6.存储引擎/upgrade_engine.md
浏览文件 @
ff78e9ab
...
...
@@ -11,7 +11,7 @@ Goods 表的存储引擎是 MyISAM,Joe 需要把它修改为 InnoDB,他应
## 答案
```
my
sql
```
sql
alter
table
goods
engine
innodb
;
```
...
...
@@ -19,7 +19,7 @@ alter table goods engine innodb;
### A
```
my
sql
```
sql
alter
table
goods
set
engine
innodb
;
```
...
...
@@ -31,7 +31,7 @@ alter table goods set engine innodb;
### C
```
my
sql
```
sql
alter
table
goods
add
engine
innodb
;
```
...
...
data/2.MySQL中阶/10.用户和权限/1.创建普通用户/create_user.md
浏览文件 @
ff78e9ab
...
...
@@ -12,7 +12,7 @@ Joe 要给数据组的 John 创建一个用户,他希望John 能够从 `192.16
## 答案
```
my
sql
```
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
```
my
sql
```
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
```
my
sql
```
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
```
my
sql
```
sql
create
user
'john'
@
'192.168.7.42'
identified
by
'goods123'
on
database
goods
;
flush
privileges
;
```
\ No newline at end of file
data/2.MySQL中阶/10.用户和权限/2.为用户授权/grant.md
浏览文件 @
ff78e9ab
...
...
@@ -11,7 +11,7 @@
## 答案
```
my
sql
```
sql
grant
select
on
table
employee
to
joe
;
```
...
...
@@ -19,30 +19,30 @@ grant select on table employee to joe;
### 权限名错误
```
my
sql
```
sql
grant
query
on
table
employee
to
joe
;
```
### 权限名错误
```
my
sql
```
sql
grant
read
on
table
employee
to
joe
;
```
### 操作关键词错误
```
my
sql
```
sql
grant
select
on
table
employee
of
joe
;
```
### 操作错误
```
my
sql
```
sql
grant
select
on
table
employee
.
*
of
joe
;
```
### 权限过高
```
my
sql
```
sql
grant
all
on
table
employee
to
joe
;
```
data/2.MySQL中阶/10.用户和权限/2.为用户授权/role.md
浏览文件 @
ff78e9ab
...
...
@@ -12,7 +12,7 @@ Joe 现在是团队的 DBA,公司数据分析组有 Fred、Alice、James、Jon
## 答案
```
my
sql
```
sql
create
role
analysis
;
grant
analysis
to
fred
,
alice
,
james
,
jone
;
grant
select
on
goods
.
*
to
analysis
;
...
...
@@ -23,13 +23,13 @@ flush privileges;
### 将来人员变动管理会很繁琐
```
my
sql
```
sql
grant
select
on
goods
.
*
to
fred
,
alice
,
james
,
jone
;
```
### 错误的语法
```
my
sql
```
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;
### 过度授权
```
my
sql
```
sql
create
role
analysis
;
grant
analysis
to
fred
,
alice
,
james
,
jone
;
grant
select
on
*
.
*
to
analysis
;
...
...
data/2.MySQL中阶/10.用户和权限/3.查看用户权限/view_privileges.md
浏览文件 @
ff78e9ab
...
...
@@ -11,7 +11,7 @@ Joe 想要查看 Fred 的 MySQL 账户 `'fred'@'%'` 的权限,他应该怎么
## 答案
```
my
sql
```
sql
show
grants
for
fred
;
```
...
...
@@ -19,18 +19,18 @@ show grants for fred;
### A
```
my
sql
```
sql
select
grants
from
fred
;
```
### B
```
my
sql
```
sql
show
privileges
for
fred
;
```
### B
```
my
sql
```
sql
show
privileges
from
fred
;
```
data/2.MySQL中阶/10.用户和权限/4.撤销用户权限/revoke.md
浏览文件 @
ff78e9ab
...
...
@@ -12,7 +12,7 @@
## 答案
```
my
sql
```
sql
revoke
select
on
trade
from
fred
;
```
...
...
@@ -20,19 +20,19 @@ revoke select on trade from fred;
### 操作错误
```
my
sql
```
sql
grant
not
select
on
trade
to
fred
;
```
### 操作关键字错误
```
my
sql
```
sql
revoke
select
on
trade
to
fred
;
```
### 指定权限错误
```
my
sql
```
sql
revoke
owned
trade
from
fred
;
```
...
...
data/2.MySQL中阶/10.用户和权限/5.修改用户密码/change_password.md
浏览文件 @
ff78e9ab
...
...
@@ -13,7 +13,7 @@ Joe 准备将这个账户的口令初始化为 `goods123fred` ,
## 答案
```
my
sql
```
sql
alter
user
'fred'
@
'%'
identified
by
'goods123fred'
password
expire
;
```
...
...
@@ -21,18 +21,18 @@ alter user 'fred'@'%' identified by 'goods123fred' password expire;
### A
```
my
sql
```
sql
alter
user
'fred'
@
'%'
identified
by
'goods123fred'
;
```
### B
```
my
sql
```
sql
alter
user
'fred'
@
'%'
set
password
'goods123fred'
;
```
### C
```
my
sql
```
sql
alter
user
'fred'
@
'%'
set
password
'goods123fred'
expire
;
```
\ No newline at end of file
data/2.MySQL中阶/10.用户和权限/6.删除用户/drop_user.md
浏览文件 @
ff78e9ab
...
...
@@ -11,7 +11,7 @@ Jane 从公司离职,Joe 需要从数据库服务器删除她的账号 `'jane'
## 答案
```
my
sql
```
sql
drop
user
'jane'
@
'%'
;
```
...
...
@@ -19,18 +19,18 @@ drop user 'jane'@'%';
### A
```
my
sql
```
sql
delete
user
'jane'
@
'%'
;
```
### B
```
my
sql
```
sql
remove
user
'jane'
@
'%'
;
```
### C
```
my
sql
```
sql
revoke
user
'jane'
@
'%'
;
```
\ No newline at end of file
data/2.MySQL中阶/10.用户和权限/7.限制用户使用资源/limit_action.md
浏览文件 @
ff78e9ab
...
...
@@ -11,7 +11,7 @@ Joe 需要限制数据分析组(role analysis)的用户, 每小时查询次
## 答案
```
my
sql
```
sql
alter
user
analysis
with
MAX_QUERIES_PER_HOUR
10000
;
```
...
...
@@ -19,25 +19,25 @@ alter user analysis with MAX_QUERIES_PER_HOUR 10000;
### A
```
my
sql
```
sql
set
user
analysis
with
MAX_QUERIES_PER_HOUR
10000
;
```
### B
```
my
sql
```
sql
alter
role
analysis
with
MAX_QUERIES_PER_HOUR
10000
;
```
### C
```
my
sql
```
sql
alter
role
analysis
with
MAX_QUERIES_PER_HOUR
=
10000
;
```
### D
```
my
sql
```
sql
alter
user
analysis
set
MAX_QUERIES_PER_HOUR
10000
;
```
data/2.MySQL中阶/2.查询进阶/2. BETWEEN/between.md
浏览文件 @
ff78e9ab
# Between
Joe 要查询 goods 表
```
my
sql
```
sql
create
table
goods
(
id
int
primary
key
auto_increment
,
category_id
int
,
...
...
@@ -23,7 +23,7 @@ create table goods(
## 答案
```
my
sql
```
sql
SELECT
*
FROM
goods
HAVING
price
BETWEEN
1000
AND
2000
;
```
...
...
@@ -32,19 +32,19 @@ SELECT * FROM goods HAVING price BETWEEN 1000 AND 2000;
### A
```
my
sql
```
sql
SELECT
*
FROM
goods
WHERE
price
BETWEEN
1000
AND
2000
;
```
### B
```
my
sql
```
sql
SELECT
*
FROM
goods
WHERE
price
>=
1000
AND
price
<=
2000
;
```
### C
```
my
sql
```
sql
SELECT
*
FROM
goods
WHERE
not
(
price
<
1000
or
price
>
2000
);
```
data/2.MySQL中阶/2.查询进阶/3.CASE/case.md
浏览文件 @
ff78e9ab
...
...
@@ -2,7 +2,7 @@
Goods 表结构如下
```
my
sql
```
sql
create
table
goods
(
id
int
primary
key
auto_increment
,
category_id
int
,
...
...
@@ -26,7 +26,7 @@ normal,这个查询应该怎么写?
## 答案
```
my
sql
```
sql
select
name
,
case
when
price
<
10
then
'cheap'
...
...
@@ -40,7 +40,7 @@ from goods;
### A
```
my
sql
```
sql
select
name
,
case
price
when
<
10
then
'cheap'
...
...
@@ -52,7 +52,7 @@ from goods;
### B
```
my
sql
```
sql
select
name
,
case
when
price
<
10
'cheap'
...
...
@@ -64,7 +64,7 @@ from goods;
### C
```
my
sql
```
sql
select
name
,
case
when
price
<
10
then
'cheap'
...
...
@@ -76,7 +76,7 @@ from goods;
### C
```
my
sql
```
sql
select
name
,
case
when
price
<
10
then
'cheap'
...
...
data/2.MySQL中阶/2.查询进阶/4.DISTINCT/distinct.md
浏览文件 @
ff78e9ab
...
...
@@ -2,7 +2,7 @@
Joe 想统计以下 goods 表
```
my
sql
```
sql
create
table
goods
(
id
int
primary
key
auto_increment
,
category_id
int
,
...
...
@@ -25,7 +25,7 @@ create table goods(
## 答案
```
my
sql
```
sql
select
count
(
distinct
price
)
from
goods
;
```
...
...
@@ -33,24 +33,24 @@ select count(distinct price) from goods;
### A
```
my
sql
```
sql
select
count
(
distinct
*
)
from
goods
;
```
### B
```
my
sql
```
sql
select
distinct
count
(
price
)
from
goods
;
```
### C
```
my
sql
```
sql
select
count
(
price
)
from
goods
;
```
### D
```
my
sql
```
sql
select
distinct
price
from
goods
;
```
data/2.MySQL中阶/2.查询进阶/5.ORDER BY/order_by.md
浏览文件 @
ff78e9ab
...
...
@@ -2,7 +2,7 @@
Joe 需要根据员工表
```
my
sql
```
sql
create
table
employee
(
id
serial
primary
key
,
...
...
@@ -23,7 +23,7 @@ create table employee
## 答案
```
my
sql
```
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
```
my
sql
```
sql
select
id
,
name
,
dept
,
salary
from
employee
order
by
dept
,
salary
;
```
### B
```
my
sql
```
sql
select
id
,
name
,
dept
,
salary
from
employee
order
by
dept
desc
,
salary
desc
;
```
### C
```
my
sql
```
sql
select
id
,
name
,
dept
,
salary
from
employee
order
by
dept
and
salary
desc
;
```
### D
```
my
sql
```
sql
select
id
,
name
,
dept
,
salary
from
employee
order
by
dept
,
salary
,
id
,
name
;
```
### E
```
my
sql
```
sql
select
id
,
name
,
dept
,
salary
from
employee
order
by
dept
,
salary
desc
;
```
data/2.MySQL中阶/2.查询进阶/6.UNION/union.md
浏览文件 @
ff78e9ab
...
...
@@ -2,7 +2,7 @@
现有员工信息表和顾客信息表如下
```
my
sql
```
sql
create
table
employee
(
id
int
primary
key
auto_increment
,
name
varchar
(
256
),
...
...
@@ -32,7 +32,7 @@ Joe 需要员工和顾客的联系方式(姓名+地址)清单,用于邮寄
## 答案
```
my
sql
```
sql
select
name
,
address
from
customer
union
...
...
@@ -44,7 +44,7 @@ from employee
### A
```
my
sql
```
sql
select
*
from
customer
union
...
...
@@ -54,7 +54,7 @@ from employee
### B
```
my
sql
```
sql
select
*
from
customer
join
employee
...
...
@@ -62,7 +62,7 @@ join employee
### C
```
my
sql
```
sql
select
*
from
customer
join
employee
on
customer
.
id
=
employee
.
id
...
...
@@ -70,14 +70,14 @@ join employee on customer.id = employee.id
### D
```
my
sql
```
sql
select
*
from
customer
,
employee
```
### E
```
my
sql
```
sql
select
name
,
address
from
customer
,
employee
```
...
...
data/2.MySQL中阶/2.查询进阶/7.正则表达式/regex.md
浏览文件 @
ff78e9ab
...
...
@@ -11,7 +11,7 @@ Joe 想要找出 goods 表中所有名称包含牛奶的冰激凌,他应该怎
## 答案
```
my
sql
```
sql
select
*
from
goods
where
name
regexp
'牛奶.*冰激凌'
;
...
...
@@ -21,7 +21,7 @@ where name regexp '牛奶.*冰激凌';
### A
```
my
sql
```
sql
select
*
from
goods
where
name
like
'牛奶%冰激凌'
...
...
@@ -30,7 +30,7 @@ where name like '牛奶%冰激凌'
### B
```
my
sql
```
sql
select
*
from
goods
where
name
like
'牛奶.*冰激凌'
;
...
...
@@ -38,7 +38,7 @@ where name like '牛奶.*冰激凌';
### C
```
my
sql
```
sql
select
*
from
goods
where
name
regexp
'牛奶冰激凌'
;
...
...
data/2.MySQL中阶/2.查询进阶/8. 分页查询/paged.md
浏览文件 @
ff78e9ab
...
...
@@ -2,7 +2,7 @@
我们有如下订单表:
```
my
sql
```
sql
create
table
orders
(
id
serial
primary
key
,
...
...
@@ -24,7 +24,7 @@ create table orders
## 答案
```
my
sql
```
sql
select
id
,
product_id
,
order_date
,
quantity
,
customer_id
from
orders
where
date
=
$
1
...
...
@@ -35,7 +35,7 @@ offset $2 limit 100;
### 缺少 limit
```
my
sql
```
sql
select
id
,
product_id
,
order_date
,
quantity
,
customer_id
from
orders
where
date
=
$
1
...
...
@@ -44,7 +44,7 @@ offset $2;
### 缺少 offset
```
my
sql
```
sql
select
id
,
product_id
,
order_date
,
quantity
,
customer_id
from
orders
where
date
=
$
1
;
...
...
@@ -52,7 +52,7 @@ where date = $1;
### 结构不对
```
my
sql
```
sql
select
id
,
product_id
,
order_date
,
quantity
,
customer_id
from
orders
where
date
=
$
1
and
...
...
data/2.MySQL中阶/3.内置函数/5.其它函数/cast.md
浏览文件 @
ff78e9ab
...
...
@@ -11,7 +11,7 @@ Joe 想要把字符串表示的整数转为整数类型,可行的方法是:
## 答案
```
my
sql
```
sql
SELECT
CAST
(
'123'
AS
SIGNED
);
```
...
...
@@ -19,7 +19,7 @@ SELECT CAST('123' AS SIGNED);
### A
```
my
sql
```
sql
select
int
(
'123'
);
```
...
...
data/2.MySQL中阶/3.内置函数/5.其它函数/convert.md
浏览文件 @
ff78e9ab
...
...
@@ -2,7 +2,7 @@
Joe 需要将下面这个查询
```
my
sql
```
sql
select
name
from
goods
;
```
...
...
@@ -17,7 +17,7 @@ select name from goods;
## 答案
```
my
sql
```
sql
select
convert
(
name
using
'gb18030'
)
from
goods
;
```
...
...
@@ -26,27 +26,27 @@ select convert(name using 'gb18030') from goods;
### A
```
my
sql
```
sql
select
str
(
name
,
'gb18303'
)
from
goods
;
```
### B
```
my
sql
```
sql
select
encode
(
decode
(
name
,
'utf8mb4'
),
'gb18303'
)
from
goods
;
```
### C
```
my
sql
```
sql
select
convert
(
name
from
'utf8mb4'
to
'gb18303'
)
from
goods
;
```
### D
```
my
sql
```
sql
select
convert
(
name
to
'gb18303'
)
from
goods
;
```
...
...
data/2.MySQL中阶/4.聚合和分组/1. 计数/count.md
浏览文件 @
ff78e9ab
...
...
@@ -16,7 +16,7 @@ mysql> select * from items;
当他执行
```
my
sql
```
sql
select
count
(
*
),
count
(
item
)
from
items
;
```
...
...
data/2.MySQL中阶/4.聚合和分组/2. 求和/sum.md
浏览文件 @
ff78e9ab
...
...
@@ -2,7 +2,7 @@
Joe 想要得到 orders 表
```
my
sql
```
sql
create
table
orders
(
id
int
primary
key
auto_increment
,
item_id
int
,
...
...
@@ -26,7 +26,7 @@ create table orders (
## 答案
```
my
sql
```
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
```
my
sql
```
sql
select
sum
(
total
)
from
orders
where
deal
and
unit_price
>
1000
;
```
### B
```
my
sql
```
sql
select
sum
(
total
)
from
orders
having
deal
and
unit_price
>
1000
;
```
### C
```
my
sql
```
sql
select
sum
(
total
)
from
orders
group
by
deal
having
unit_price
>
1000
;
```
### D
```
my
sql
```
sql
select
sum
(
total
)
from
orders
having
deal
and
unit_price
>
1000
;
```
\ No newline at end of file
data/2.MySQL中阶/4.聚合和分组/3.最小值/min.md
浏览文件 @
ff78e9ab
...
...
@@ -2,7 +2,7 @@
Joe 想要得到 employee 表
```
my
sql
```
sql
create
table
employee
(
id
serial
primary
key
,
...
...
@@ -23,7 +23,7 @@ create table employee
## 答案
```
my
sql
```
sql
select
dept
,
min
(
salary
)
from
employee
group
by
dept
;
```
...
...
@@ -31,24 +31,24 @@ select dept, min(salary) from employee group by dept;
### A
```
my
sql
```
sql
select
dept
,
min
(
salary
)
from
employee
;
```
### B
```
my
sql
```
sql
select
dept
,
min
(
salary
)
from
employee
;
```
### C
```
my
sql
```
sql
select
dept
,
min
(
salary
)
from
employee
;
```
### D
```
my
sql
```
sql
select
dept
,
min
(
total
)
from
employee
;
```
\ No newline at end of file
data/2.MySQL中阶/4.聚合和分组/4. 最大值/max.md
浏览文件 @
ff78e9ab
...
...
@@ -2,7 +2,7 @@
利用员工信息表:
```
my
sql
```
sql
create
table
employee
(
id
serial
primary
key
,
...
...
@@ -23,7 +23,7 @@ Joe 做了一些关于 max 函数的练习,其中不正确的是:
## 答案
```
my
sql
```
sql
select
id
,
dept
,
max
(
salary
)
as
salary
,
name
from
employee
group
by
dept
...
...
@@ -35,7 +35,7 @@ group by dept
### A
```
my
sql
```
sql
select
dept
,
max
(
salary
)
as
salary
from
employee
group
by
dept
...
...
@@ -45,7 +45,7 @@ group by dept
### B
```
my
sql
```
sql
select
max
(
salary
)
as
salary
from
employee
```
...
...
@@ -54,7 +54,7 @@ from employee
### C
```
my
sql
```
sql
select
dept
,
sum
(
salary
)
from
employee
group
by
dept
...
...
@@ -65,7 +65,7 @@ having max(salary) < 20000
### D
```
my
sql
```
sql
select
dept
,
min
(
salary
)
from
employee
group
by
dept
...
...
data/2.MySQL中阶/4.聚合和分组/5. 平均值/avg.md
浏览文件 @
ff78e9ab
...
...
@@ -2,7 +2,7 @@
Joe 想要得到 employee 表
```
my
sql
```
sql
create
table
employee
(
id
serial
primary
key
,
...
...
@@ -23,7 +23,7 @@ create table employee
## 答案
```
my
sql
```
sql
select
dept
,
avg
(
salary
)
from
employee
group
by
dept
;
```
...
...
@@ -31,24 +31,24 @@ select dept, avg(salary) from employee group by dept;
### A
```
my
sql
```
sql
select
dept
,
avg
(
salary
)
from
employee
;
```
### B
```
my
sql
```
sql
select
dept
,
avg
(
salary
)
from
employee
;
```
### C
```
my
sql
```
sql
select
dept
,
avg
(
salary
)
from
employee
;
```
### D
```
my
sql
```
sql
select
dept
,
avg
(
salary
)
from
employee
;
```
\ No newline at end of file
data/2.MySQL中阶/4.聚合和分组/6.HAVING/having.md
浏览文件 @
ff78e9ab
...
...
@@ -2,7 +2,7 @@
Joe 要从 employee 表
```
my
sql
```
sql
create
table
employee
(
id
serial
primary
key
,
...
...
@@ -23,7 +23,7 @@ create table employee
## 答案
```
my
sql
```
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
```
my
sql
```
sql
select
dept
from
employee
group
by
dept
where
sum
(
salary
)
>
100000
;
```
### B
```
my
sql
```
sql
select
dept
from
employee
where
sum
(
salary
)
>
100000
group
by
dept
;
```
### C
```
my
sql
```
sql
select
dept
from
employee
where
sum
(
salary
)
>
100000
order
by
dept
;
```
### D
```
my
sql
```
sql
select
dept
from
employee
group
by
dept
where
sum
(
salary
)
>
100000
;
```
...
...
data/2.MySQL中阶/5.子查询/1.相关子查询/subquery.md
浏览文件 @
ff78e9ab
...
...
@@ -2,7 +2,7 @@
现有员工表
```
my
sql
```
sql
create
table
employee
(
id
serial
primary
key
,
...
...
@@ -23,7 +23,7 @@ Joe 希望找出比销售部(dept 为 sale)工资最高的员工工资更高
## 答案
```
my
sql
```
sql
select
id
,
name
,
dept
,
salary
from
employee
where
salary
>
(
select
max
(
salary
)
...
...
@@ -35,7 +35,7 @@ where salary > (select max(salary)
### A
```
my
sql
```
sql
select
id
,
name
,
dept
,
salary
from
employee
where
dept
=
'sale'
...
...
@@ -45,7 +45,7 @@ having salary > max(salary)
### B
```
my
sql
```
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
```
my
sql
```
sql
select
id
,
name
,
dept
,
salary
from
employee
having
salary
>
(
select
max
(
salary
)
from
employee
where
dept
=
'sale'
)
...
...
data/2.MySQL中阶/5.子查询/2. ANY/any.md
浏览文件 @
ff78e9ab
...
...
@@ -2,7 +2,7 @@
Joe 想要从员工表
```
my
sql
```
sql
create
table
employee
(
id
int
primary
key
auto_increment
,
name
varchar
(
256
),
...
...
@@ -22,7 +22,7 @@ create table employee(
## 答案
```
my
sql
```
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
```
my
sql
```
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
```
my
sql
```
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
```
my
sql
```
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
...
...
data/2.MySQL中阶/5.子查询/3.ALL/all.md
浏览文件 @
ff78e9ab
...
...
@@ -2,7 +2,7 @@
Joe 想从员工表
```
my
sql
```
sql
create
table
employee
(
id
int
primary
key
auto_increment
,
dept_id
int
,
...
...
@@ -22,7 +22,7 @@ create table employee(
## 答案
```
my
sql
```
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
```
my
sql
```
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
```
my
sql
```
sql
select
id
,
name
,
dept
from
employee
as
o
where
'assistant'
!=
all
(
select
post
from
employee
as
i
where
o
.
dept
=
i
.
dept
);
```
### C
```
my
sql
```
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
```
my
sql
```
sql
select
id
,
name
,
dept
from
employee
as
o
where
'assistant'
!=
ANY
(
select
post
from
employee
as
i
where
o
.
dept
=
i
.
dept
);
...
...
data/2.MySQL中阶/5.子查询/4.EXISTS/exists.md
浏览文件 @
ff78e9ab
...
...
@@ -2,7 +2,7 @@
Joe 想从员工表
```
my
sql
```
sql
create
table
employee
(
id
int
primary
key
auto_increment
,
dept_id
int
,
...
...
@@ -23,7 +23,7 @@ create table employee(
## 答案
```
my
sql
```
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
```
my
sql
```
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
```
my
sql
```
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
```
my
sql
```
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
```
my
sql
```
sql
select
id
,
name
,
dept
from
employee
as
o
where
'assistant'
=
not
exists
(
select
post
from
employee
as
i
where
o
.
dept
=
i
.
dept
);
...
...
data/2.MySQL中阶/5.子查询/5. IN/in.md
浏览文件 @
ff78e9ab
...
...
@@ -2,7 +2,7 @@
Joe 想要从员工表
```
my
sql
```
sql
create
table
employee
(
id
int
primary
key
auto_increment
,
dept_id
int
,
...
...
@@ -22,7 +22,7 @@ create table employee(
## 答案
```
my
sql
```
sql
select
id
,
dept
,
name
,
post
from
employee
where
dept
in
(
'dev'
,
'hr'
);
...
...
@@ -32,7 +32,7 @@ where dept in ('dev', 'hr');
### A
```
my
sql
```
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
```
my
sql
```
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
```
my
sql
```
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
```
my
sql
```
sql
select
id
,
dept
,
name
,
post
from
employee
where
dept
in
(
'dev'
or
'hr'
);
...
...
data/2.MySQL中阶/5.子查询/6. 列子查询/in_column.md
浏览文件 @
ff78e9ab
...
...
@@ -2,7 +2,7 @@
Joe 打算写一个查询,根据员工表
```
my
sql
```
sql
create
table
employee
(
id
int
primary
key
auto_increment
,
...
...
@@ -23,7 +23,7 @@ create table employee
## 答案
```
my
sql
```
sql
select
distinct
(
dept
)
as
dept
,
(
select
count
(
*
)
from
employee
as
i
...
...
@@ -35,7 +35,7 @@ from employee as o;
### A
```
my
sql
```
sql
select
distinct
(
dept
)
as
dept
,
(
select
count
(
*
)
from
employee
as
i
)
as
emp
...
...
@@ -44,7 +44,7 @@ from employee as o;
### B
```
my
sql
```
sql
select
distinct
(
dept
)
as
dept
,
(
select
count
(
*
)
from
employee
...
...
@@ -54,7 +54,7 @@ from employee
### C
```
my
sql
```
sql
select
dept
as
dept
,
(
select
count
(
*
)
from
employee
as
i
...
...
data/2.MySQL中阶/6.连接查询/1.INNER JOIN/join_self.md
浏览文件 @
ff78e9ab
...
...
@@ -2,7 +2,7 @@
现有 node 表如下:
```
my
sql
```
sql
create
table
node
(
id
int
primary
key
auto_increment
,
pid
int
,
...
...
@@ -22,7 +22,7 @@ create table node(
## 答案
```
my
sql
```
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
```
my
sql
```
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
```
my
sql
```
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
```
my
sql
```
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
```
my
sql
```
sql
select
l
.
id
as
parent_id
,
l
.
content
as
parent_content
,
r
.
id
as
child_id
,
...
...
data/2.MySQL中阶/6.连接查询/2. LEFT JOIN/left_join.md
浏览文件 @
ff78e9ab
...
...
@@ -2,7 +2,7 @@
现有部门表
```
my
sql
```
sql
create
table
department
(
id
int
primary
key
auto_increment
,
name
varchar
(
256
)
...
...
@@ -11,7 +11,7 @@ create table department(
和员工表
```
my
sql
```
sql
create
table
employee
(
id
int
primary
key
auto_increment
,
dept_id
int
,
...
...
@@ -31,7 +31,7 @@ Joe 想要列出所有的部门,如果这个部门有部门助理(post 为 `
## 答案
```
my
sql
```
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
```
my
sql
```
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
```
my
sql
```
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
```
my
sql
```
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
```
my
sql
```
sql
select
d
.
id
,
d
.
name
,
e
.
name
as
assistant
from
employee
as
e
left
join
department
as
d
on
e
.
dept
=
d
.
id
...
...
data/2.MySQL中阶/6.连接查询/3. RIGHT JOIN/right_join.md
浏览文件 @
ff78e9ab
...
...
@@ -2,7 +2,7 @@
现有部门表
```
my
sql
```
sql
create
table
department
(
id
int
primary
key
auto_increment
,
name
varchar
(
256
)
...
...
@@ -11,7 +11,7 @@ create table department(
和员工表
```
my
sql
```
sql
create
table
employee
(
id
int
primary
key
auto_increment
,
dept_id
int
,
...
...
@@ -32,7 +32,7 @@ create table employee(
## 答案
```
my
sql
```
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
```
my
sql
```
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
```
my
sql
```
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
```
my
sql
```
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
```
my
sql
```
sql
select
e
.
id
,
e
.
name
,
e
.
dept
from
department
as
d
right
join
employee
as
e
on
d
.
id
=
e
.
dept
...
...
data/2.MySQL中阶/6.连接查询/4. CROSS JOIN/cross_join.md
浏览文件 @
ff78e9ab
...
...
@@ -2,7 +2,7 @@
Joe 需要生成 goods 表
```
my
sql
```
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 表
```
my
sql
```
sql
create
table
size
(
id
int
primary
key
auto_increment
,
name
varchar
(
16
)
...
...
@@ -33,7 +33,7 @@ create table size(
## 答案
```
my
sql
```
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
```
my
sql
```
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
```
my
sql
```
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
```
my
sql
```
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
```
my
sql
```
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
```
my
sql
```
sql
select
g
.
id
,
g
.
name
,
s
.
name
as
size
from
goods
as
g
outter
join
size
as
s
...
...
data/2.MySQL中阶/6.连接查询/5. 复杂连接/salary.md
浏览文件 @
ff78e9ab
...
...
@@ -2,7 +2,7 @@
现有员工信息表如下:
```
my
sql
```
sql
create
table
employee
(
id
serial
primary
key
,
...
...
@@ -23,7 +23,7 @@ create table employee
## 答案
```
my
sql
```
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 不匹配
```
my
sql
```
sql
select
id
,
name
,
dept
,
max
(
salary
)
from
employee
group
by
dept
;
...
...
@@ -44,7 +44,7 @@ group by dept;
### group by 不对
```
my
sql
```
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 不对
```
my
sql
```
sql
select
id
,
name
,
dept
,
max
(
salary
)
from
employee
group
by
dept
,
id
,
name
...
...
@@ -61,7 +61,7 @@ having salary = max(salary);
### 结构错误
```
my
sql
```
sql
select
id
,
name
,
dept
,
max
(
salary
)
from
employee
where
salary
=
max
(
salary
)
...
...
data/2.MySQL中阶/7. 索引/2.创建索引/create_index.md
浏览文件 @
ff78e9ab
...
...
@@ -2,7 +2,7 @@
Joe 想给 Goods 表
```
my
sql
```
sql
create
table
goods
(
id
int
primary
key
auto_increment
,
category_id
int
,
...
...
@@ -26,7 +26,7 @@ create table goods(
## 答案
```
my
sql
```
sql
create
index
idx_goods_category
on
goods
(
category_id
);
```
...
...
@@ -34,18 +34,18 @@ create index idx_goods_category on goods(category_id);
### A
```
my
sql
```
sql
create
unique
index
idx_goods_category
on
goods
(
category_id
);
```
### B
```
my
sql
```
sql
create
index
idx_goods_category
on
goods
(
category_id
);
```
### C
```
my
sql
```
sql
alter
table
goods
add
unique
index
(
category_id
);
```
\ No newline at end of file
data/2.MySQL中阶/7. 索引/3.删除索引/drop_index.md
浏览文件 @
ff78e9ab
...
...
@@ -13,13 +13,13 @@ Joe 想要删除创建在 goods 表创建的索引,但是他已经忘了这个
执行
```
my
sql
```
sql
show
index
from
goods
;
```
查看 goods 表的索引(假设查到是 idx_goods_category),然后执行
```
my
sql
```
sql
alter
table
goods
drop
index
idx_goods_category
;
```
...
...
@@ -29,13 +29,13 @@ alter table goods drop index idx_goods_category;
执行
```
my
sql
```
sql
show
index
from
goods
;
```
查看 goods 表的索引(假设查到是 idx_goods_category),然后执行
```
my
sql
```
sql
alter
table
goods
delete
index
idx_goods_category
;
```
...
...
@@ -43,13 +43,13 @@ alter table goods delete index idx_goods_category;
执行
```
my
sql
```
sql
show
index
from
goods
;
```
查看 goods 表的索引(假设查到是 idx_goods_category),然后执行
```
my
sql
```
sql
alter
table
goods
remove
index
idx_goods_category
;
```
...
...
@@ -57,13 +57,13 @@ alter table goods remove index idx_goods_category;
执行
```
my
sql
```
sql
show
index
from
goods
;
```
查看 goods 表的索引(假设查到是 idx_goods_category),然后执行
```
my
sql
```
sql
alter
table
goods
drop
idx_goods_category
;
```
...
...
data/3.MySQL高阶/1.深入索引/1.唯一索引/unique.md
浏览文件 @
ff78e9ab
...
...
@@ -2,7 +2,7 @@
Goods 表结构如下:
```
my
sql
```
sql
create
table
goods
(
id
int
primary
key
auto_increment
,
category_id
int
,
...
...
@@ -24,7 +24,7 @@ Joe 需要确保同一个类型下没有重名的商品,他应该怎么做?
## 答案
```
my
sql
```
sql
alter
table
goods
add
unique
index
(
category_id
,
name
);
```
...
...
@@ -32,18 +32,18 @@ alter table goods add unique index (category_id, name);
### A
```
my
sql
```
sql
alter
table
goods
add
index
(
category_id
,
name
);
```
### B
```
my
sql
```
sql
alter
table
goods
add
unique
index
(
category_id
+
name
);
```
### C
```
my
sql
```
sql
alter
table
goods
add
unique
index
(
concat
(
category_id
,
name
));
```
data/3.MySQL高阶/1.深入索引/2.全值匹配/total_index.md
浏览文件 @
ff78e9ab
...
...
@@ -2,7 +2,7 @@
Goods 表结构如下:
```
my
sql
```
sql
create
table
goods
(
id
int
primary
key
auto_increment
,
category_id
int
,
...
...
@@ -24,7 +24,7 @@ create table goods(
## 答案
```
my
sql
```
sql
alter
table
goods
add
index
(
name
,
price
);
```
...
...
@@ -38,12 +38,12 @@ alter table goods add index (name, price);
建立一个计算字段:
```
my
sql
```
sql
alter
table
goods
add
summary
varchar
(
1024
)
generated
always
as
(
concat
(
name
,
'('
,
0
.
5
,
')'
));
```
### C
```
my
sql
```
sql
alter
table
goods
add
index
(
concat
(
name
,
price
));
```
\ No newline at end of file
data/3.MySQL高阶/1.深入索引/3.匹配顺序/match_fields.md
浏览文件 @
ff78e9ab
...
...
@@ -2,7 +2,7 @@
Goods 表结构如下:
```
my
sql
```
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
将该查询改写为
```
my
sql
```
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=?;
将该查询改写为
```
my
sql
```
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= (?, ?
将该查询改写为
```
my
sql
```
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
将该查询改写为
```
my
sql
```
sql
select
id
,
category_id
,
name
,
price
from
goods
where
not
(
category_id
!=?
)
and
not
(
name
!=
?
);
```
data/3.MySQL高阶/1.深入索引/4.组合索引/combinate.md
浏览文件 @
ff78e9ab
...
...
@@ -2,7 +2,7 @@
Goods 表结构如下:
```
my
sql
```
sql
create
table
goods
(
id
int
primary
key
auto_increment
,
category_id
int
,
...
...
@@ -26,7 +26,7 @@ Joe 应该如何优化?
## 答案
```
my
sql
```
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
```
my
sql
```
sql
alter
table
goods
add
index
(
`stock-id`
and
category_id
and
name
);
```
### B
```
my
sql
```
sql
alter
table
goods
add
index
(
concat
(
stock
,
category_id
,
name
));
```
### C
```
my
sql
```
sql
alter
table
goods
add
index
(
`stock-id`
+
category_id
+
name
);
```
data/3.MySQL高阶/1.深入索引/5.空间索引/geo_index.md
浏览文件 @
ff78e9ab
...
...
@@ -2,7 +2,7 @@
Goods 数据库中有一个 shop 表,其中包含如下字段:
```
my
sql
```
sql
create
table
shop
(
id
int
primary
key
auto_increment
,
location
GEOMETRY
...
...
@@ -21,7 +21,7 @@ create table shop (
## 答案
```
my
sql
```
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
```
my
sql
```
sql
alter
table
shop
add
INDEX
geo_index
(
location
);
```
### B
```
my
sql
```
sql
alter
table
shop
add
INDEX
location
;
```
### C
```
my
sql
```
sql
alter
table
shop
modify
location
GEOMETRY
not
null
;
alter
table
shop
add
INDEX
location
;
```
### D
```
my
sql
```
sql
alter
table
shop
modify
location
GEOMETRY
not
null
;
alter
table
shop
add
INDEX
location
;
```
data/3.MySQL高阶/1.深入索引/6.全文索引/full_text_index.md
浏览文件 @
ff78e9ab
...
...
@@ -2,7 +2,7 @@
Shop 表的部分字段如下:
```
my
sql
```
sql
create
table
shop
(
id
int
primary
key
auto_increment
,
description
varchar
(
8000
)
...
...
@@ -21,7 +21,7 @@ create table shop (
## 答案
```
my
sql
```
sql
alter
table
shop
add
fulltext
(
description
);
```
...
...
@@ -29,18 +29,18 @@ alter table shop add fulltext(description);
### A
```
my
sql
```
sql
alter
table
shop
add
index
fulltext
(
description
);
```
### B
```
my
sql
```
sql
alter
table
shop
create
fulltext
(
description
);
```
### C
```
my
sql
```
sql
alter
table
shop
alter
description
add
fulltext
(
description
);
```
\ No newline at end of file
data/3.MySQL高阶/1.深入索引/7.隐藏索引/invisible.md
浏览文件 @
ff78e9ab
...
...
@@ -2,7 +2,7 @@
Shop 表的部分字段如下:
```
my
sql
```
sql
create
table
shop
(
id
int
primary
key
auto_increment
,
description
varchar
(
8000
),
...
...
@@ -27,13 +27,13 @@ Joe 应该怎么做?
先执行
```
my
sql
```
sql
alter
table
shop
alter
index
description
invisible
;
```
将索引隐藏,观察确认没有影响后再执行
```
my
sql
```
sql
alter
table
shop
drop
index
description
;
```
...
...
@@ -46,7 +46,7 @@ alter table shop drop index description;
先备份 shop 表,然后执行
```
my
sql
```
sql
alter
table
shop
drop
index
description
;
```
删除,有问题的话从备份文件恢复。
...
...
@@ -59,13 +59,13 @@ alter table shop drop index description;
先执行
```
my
sql
```
sql
alter
table
shop
alter
index
description
invisible
;
```
将索引隐藏,确认后再执行
```
my
sql
```
sql
alter
table
shop
alter
index
description
visible
;
```
...
...
data/3.MySQL高阶/1.深入索引/8.函数和表达式索引/daily_payment.md
浏览文件 @
ff78e9ab
...
...
@@ -2,7 +2,7 @@
数据分析组需要经常执行以下查询生成从昨天到之前某一天的交易量统计
```
my
sql
```
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;
建立表达式索引
```
my
sql
```
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)));
建立视图
```
my
sql
```
sql
create
view
view_daily_payment
as
select
date
(
payment_date
)
as
day
,
amount
from
payment
;
```
然后在视图 view_daily_payment 上执行
```
my
sql
```
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 列上建立索引
```
my
sql
```
sql
create
index
idx_payment_date
on
payment
(
payment_date
);
```
...
...
@@ -74,13 +74,13 @@ create index idx_payment_date on payment(payment_date);
建立计算列
```
my
sql
```
sql
alter
table
payment
add
day
date
generated
always
as
(
date
(
payment_date
))
stored
;
```
然后使用它改写查询
```
my
sql
```
sql
select
day
as
day
,
sum
(
amount
)
from
payment
where
day
between
$
1
and
date
(
'yesterday'
)
...
...
data/3.MySQL高阶/2.SQL高级技巧/1.CTE和递归查询/continuous.md
浏览文件 @
ff78e9ab
...
...
@@ -3,7 +3,7 @@
SmartMarket 交易所的系统中,所有订单在生成时,都从一个 oracle Sequence 中获取唯一的
序列号,完成交易计算后各个撮合程序将其插入如下的 orders 表中:
```
my
sql
```
sql
create
table
orders
(
id
integer
primary
key
,
...
...
@@ -27,7 +27,7 @@ create table orders
## 答案
```
my
sql
```
sql
with
recursive
r
(
id
)
as
(
select
id
from
orders
where
id
=
$
1
...
...
@@ -48,7 +48,7 @@ from orders
### B
```
my
sql
```
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
```
my
sql
```
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
```
my
sql
```
sql
with
r
as
(
select
id
from
orders
where
id
=
$
1
...
...
data/3.MySQL高阶/2.SQL高级技巧/1.CTE和递归查询/to_root.md
浏览文件 @
ff78e9ab
...
...
@@ -2,7 +2,7 @@
现有一个表 node
```
my
sql
```
sql
create
table
node
(
id
int
primary
key
auto_increment
,
...
...
@@ -24,7 +24,7 @@ create table node
## 答案
```
my
sql
```
sql
with
recursive
t
(
id
,
pid
,
val
)
as
(
select
id
,
pid
,
val
from
node
...
...
@@ -42,7 +42,7 @@ from node
### 没有递归定义
```
my
sql
```
sql
with
t
as
(
select
id
,
pid
,
val
from
node
...
...
@@ -58,7 +58,7 @@ from node
### 平凡的连接查询无法处理递归问题
```
my
sql
```
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;
### 子查询无法处理递归问题
```
my
sql
```
sql
select
node
.
id
,
node
.
pid
,
node
val
from
node
as
t
where
t
.
pid
=
(
select
id
from
t
where
id
=
t
.
pid
)
...
...
data/3.MySQL高阶/2.SQL高级技巧/2.Window Function/salary.md
浏览文件 @
ff78e9ab
...
...
@@ -2,7 +2,7 @@
现有员工信息表如下:
```
my
sql
```
sql
create
table
employee
(
id
serial
primary
key
,
...
...
@@ -23,7 +23,7 @@ create table employee
## 答案
```
my
sql
```
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;
### 结构错误
```
my
sql
```
sql
select
id
,
name
,
dept
,
max
(
salary
)
as
salary
from
employee
group
by
dept
...
...
@@ -43,7 +43,7 @@ having id < 6;
### 结构错误
```
my
sql
```
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;
### 结构错误
```
my
sql
```
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
### 结构错误
```
my
sql
```
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;
### 结构错误
```
my
sql
```
sql
select
id
,
name
,
dept
,
salary
,
rank
()
as
r
over
(
partition
by
dept
order
by
salary
desc
)
from
employee
where
r
<=
5
;
...
...
data/3.MySQL高阶/2.SQL高级技巧/3.透视表 /pivot.md
浏览文件 @
ff78e9ab
...
...
@@ -2,7 +2,7 @@
现有销售记录表
```
my
sql
```
sql
create
table
sales
(
id
serial
primary
key
,
sku_id
integer
not
null
,
...
...
@@ -23,7 +23,7 @@ create index on sales(created_at);
## 答案
```
my
sql
```
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;
### 格式不相符
```
my
sql
```
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;
### 计算逻辑错误
```
my
sql
```
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);
### 计算格式错误
```
my
sql
```
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
,
...
...
data/3.MySQL高阶/2.SQL高级技巧/4.Double Not Exists/DoubleNotExists.md
浏览文件 @
ff78e9ab
...
...
@@ -2,7 +2,7 @@
风控部门的数据库中有一组关于招投标的数据,关键信息如下:
```
my
sql
```
sql
-- 招标项目
create
table
invitation
(
...
...
@@ -42,7 +42,7 @@ Joe 想要找出参与了所有投标的企业(有围标嫌疑),那么这
## 答案
```
my
sql
```
sql
select
*
from
company
where
not
exists
(
...
...
@@ -61,7 +61,7 @@ where not exists(
### A
```
my
sql
```
sql
select
*
from
company
where
id
=
all
(
select
company_id
...
...
@@ -70,7 +70,7 @@ where id = all (select company_id
### B
```
my
sql
```
sql
select
*
from
company
where
id
=
any
(
select
company_id
...
...
@@ -79,7 +79,7 @@ where id = any (select company_id
### C
```
my
sql
```
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
```
my
sql
```
sql
select
*
from
company
where
exists
(
...
...
data/3.MySQL高阶/2.SQL高级技巧/5.写入和冲突/score.md
浏览文件 @
ff78e9ab
...
...
@@ -2,7 +2,7 @@
现有一个表
```
my
sql
```
sql
create
table
book_in
(
login
integer
primary
key
,
score
integer
default
0
...
...
@@ -21,7 +21,7 @@ create table book_in(
## 答案
```
my
sql
```
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
```
my
sql
```
sql
try
insert
into
book_in
(
login
,
score
)
values
(
$
1
,
$
2
);
catch
...
...
@@ -40,18 +40,18 @@ finally
### B
```
my
sql
```
sql
insert
into
book_in
(
login
,
score
)
select
$
1
,
$
2
;
```
### C
```
my
sql
```
sql
replace
book_in
(
login
,
score
)
select
$
1
,
$
2
;
```
### D
```
my
sql
```
sql
upsert
into
book_in
(
login
,
score
)
select
$
1
,
$
2
;
```
data/3.MySQL高阶/2.SQL高级技巧/6.事务/transaction.md
浏览文件 @
ff78e9ab
...
...
@@ -2,13 +2,13 @@
现有 test1 表如下
```
my
sql
```
sql
create
table
test1
(
a
integer
primary
key
);
```
我们执行下面的语句
```
my
sql
```
sql
CREATE
PROCEDURE
transaction_test1
()
BEGIN
declare
idx
int
;
...
...
data/3.MySQL高阶/3. 过程化编程/1.IF/if.md
浏览文件 @
ff78e9ab
...
...
@@ -17,7 +17,7 @@ Goods 数据库中有一个名为 trade 的存储过程,封装了交易过程
## 答案
```
my
sql
```
sql
set
@
counter
=
@
counter
+
1
;
if
@
counter
%
1000
=
0
then
set
@
total_price
=
@
total_price
*
0
.
8
;
...
...
@@ -28,7 +28,7 @@ end if;
### A
```
my
sql
```
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
```
my
sql
```
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
```
my
sql
```
sql
if
@
counter
%
1000
=
0
begin
;
set
@
total_price
=
@
total_price
*
0
.
8
;
end
;
...
...
@@ -54,7 +54,7 @@ end;
### D
```
my
sql
```
sql
set
@
counter
++
;
if
@
counter
%
1000
=
0
then
begin
select
@
total_price
=
@
total_price
*
0
.
8
;
...
...
data/3.MySQL高阶/3. 过程化编程/2.LOOP/loop.md
浏览文件 @
ff78e9ab
...
...
@@ -13,7 +13,7 @@
## 答案
```
my
sql
```
sql
-- ...
trade
:
LOOP
if
@
price
>
1000
then
...
...
@@ -33,7 +33,7 @@ end LOOP trace;
### A
```
my
sql
```
sql
-- ...
trade
:
LOOP
if
@
price
>
1000
then
...
...
@@ -49,7 +49,7 @@ end LOOP trace;
### B
```
my
sql
```
sql
-- ...
trade
:
LOOP
if
@
price
>
1000
then
...
...
@@ -67,7 +67,7 @@ end LOOP trace;
### C
```
my
sql
```
sql
-- ...
trade
:
LOOP
if
@
price
>
1000
then
...
...
@@ -85,7 +85,7 @@ end LOOP trace;
### D
```
my
sql
```
sql
-- ...
trade
:
LOOP
if
@
price
>
1000
then
...
...
data/3.MySQL高阶/3. 过程化编程/3.REPEAT/repeat.md
浏览文件 @
ff78e9ab
...
...
@@ -2,7 +2,7 @@
交易过程 trade 中有一个遍历交易项的循环,当累计的总交易额
`@total_price`
超过 20000, 这个循环就结束
```
my
sql
```
sql
-- ...
trade
:
LOOP
-- ...
...
...
@@ -26,7 +26,7 @@ end LOOP trace;
## 答案
```
my
sql
```
sql
trade
:
REPEATE
-- 省略交易过程
UNTIL
@
total_price
>
20000
...
...
@@ -37,7 +37,7 @@ END REPATE trade;
### A
```
my
sql
```
sql
trade
:
REPEATE
UNTIL
@
total_price
>
20000
-- 省略交易过程
...
...
@@ -46,7 +46,7 @@ END REPATE trade;
### B
```
my
sql
```
sql
REPEATE
@
total_price
>
20000
-- 省略交易过程
END
REPATE
;
...
...
@@ -54,7 +54,7 @@ END REPATE;
### C
```
my
sql
```
sql
trade
:
REPEATE
-- 省略交易过程
IF
@
total_price
>
20000
...
...
@@ -63,7 +63,7 @@ END REPATE trade;
### D
```
my
sql
```
sql
trade
:
REPEATE
IF
@
total_price
>
20000
-- 省略交易过程
...
...
data/3.MySQL高阶/3. 过程化编程/4.WHILE/while.md
浏览文件 @
ff78e9ab
...
...
@@ -2,7 +2,7 @@
交易过程 trade 中有一个遍历交易项的循环,当累计的总交易额
`@total_price`
超过 20000, 这个循环就结束
```
my
sql
```
sql
-- ...
trade
:
LOOP
-- ...
...
...
@@ -26,7 +26,7 @@ end LOOP trace;
## 答案
```
my
sql
```
sql
trade
:
WHILE
@
total_price
>
20000
-- 省略交易过程
END
WHILE
trade
;
...
...
@@ -36,7 +36,7 @@ END WHILE trade;
### A
```
my
sql
```
sql
trade
:
DO
-- 省略交易过程
WHILE
@
total_price
>
20000
;
...
...
@@ -44,7 +44,7 @@ WHILE @total_price > 20000;
### B
```
my
sql
```
sql
trade
:
WHILE
@
total_price
>
20000
-- 省略交易过程
END
WHILE
trade
;
...
...
@@ -52,7 +52,7 @@ END WHILE trade;
### C
```
my
sql
```
sql
trade
:
WHILE
@
total_price
>
20000
DO
-- 省略交易过程
END
WHILE
trade
;
...
...
@@ -60,7 +60,7 @@ END WHILE trade;
### D
```
my
sql
```
sql
trade
:
WHILE
@
total_price
>
20000
-- 省略交易过程
END
WHILE
;
...
...
data/3.MySQL高阶/3. 过程化编程/5. 游标/cursor.md
浏览文件 @
ff78e9ab
...
...
@@ -2,7 +2,7 @@
Joe 需要开发一个存储过程 make_trade,从 orders 表
```
my
sql
```
sql
create
table
orders
(
id
int
primary
key
auto_increment
,
price
decimal
(
12
,
4
),
...
...
@@ -13,7 +13,7 @@ create table orders (
中,按 id 从小到大加载订单数据,生成交易单,写入 trade 表
```
my
sql
```
sql
create
table
trade
(
id
int
primary
key
auto_increment
,
total
decimal
(
12
,
4
)
...
...
@@ -36,7 +36,7 @@ create table trade (
## 答案
```
my
sql
```
sql
create
procedure
make_trade
()
begin
DECLARE
done
INT
DEFAULT
FALSE
;
...
...
@@ -70,7 +70,7 @@ end;
### A
```
my
sql
```
sql
create
procedure
make_trade
()
begin
DECLARE
done
INT
DEFAULT
FALSE
;
...
...
@@ -97,7 +97,7 @@ end;
### B
```
my
sql
```
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
```
my
sql
```
sql
create
procedure
make_trade
()
begin
DECLARE
done
INT
DEFAULT
FALSE
;
...
...
@@ -139,7 +139,7 @@ end;
### D
```
my
sql
```
sql
create
procedure
make_trade
()
begin
DECLARE
done
INT
DEFAULT
FALSE
;
...
...
data/3.MySQL高阶/4.设计优化/1.生成列/generated.md
浏览文件 @
ff78e9ab
...
...
@@ -2,7 +2,7 @@
Joe 需要为 Points 表
```
my
sql
```
sql
create
table
points
(
id
int
primary
key
auto_increment
,
x
float
,
...
...
@@ -21,7 +21,7 @@ create table points(
## 答案
```
my
sql
```
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
```
my
sql
```
sql
create
generated
modulus
on
table
points
as
(
sqrt
(
x
*
x
+
y
*
y
));
```
### B
```
my
sql
```
sql
alter
table
points
add
modulus
generated
always
as
(
sqrt
(
x
*
x
+
y
*
y
));
```
### C
```
my
sql
```
sql
alter
table
points
add
modulus
float
generated
sqrt
(
x
*
x
+
y
*
y
);
```
data/3.MySQL高阶/4.设计优化/2. 范式设计/customer_order.md
浏览文件 @
ff78e9ab
...
...
@@ -2,7 +2,7 @@
Goods 中有客户/订单系统如下:
```
my
sql
```
sql
create
table
customers
(
id
serial
primary
key
,
...
...
data/3.MySQL高阶/4.设计优化/4.增加中间表/daily_payment2.md
浏览文件 @
ff78e9ab
...
...
@@ -3,7 +3,7 @@
# 每日报表
分析过去一段时间的查询数据,Joe 发现 payment 表
```
my
sql
```
sql
create
table
payment
(
payment_id
int
primary
key
auto_increment
,
customer_id
int
,
...
...
@@ -16,7 +16,7 @@ create table payment(
每天的订单量很大,下面这个查询的统计过程占用了大多数数据库资源,查询不会
早于当天,总是在历史上某一个日期段内查询
```
my
sql
```
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
使用
```
my
sql
```
sql
select
day
,
amount
from
view_daily_payment
where
day
between
$
1
and
$
2
;
```
进行查询。并且每天定时执行一次刷新命令
```
my
sql
```
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 列上建立索引
```
my
sql
```
sql
create
index
idx_payment_date
on
payment
(
payment_date
);
```
...
...
@@ -76,13 +76,13 @@ create index idx_payment_date on payment(payment_date);
建立计算列
```
my
sql
```
sql
alter
table
payment
add
day
date
generated
always
as
(
payment_date
::
date
)
stored
```
然后使用它改写查询
```
my
sql
```
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;
建立表达式索引
```
my
sql
```
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)));
建立视图
```
my
sql
```
sql
create
view
view_daily_payment
as
select
date
(
payment_date
)
as
day
,
amount
from
payment
;
```
然后在视图 view_daily_payment 上执行
```
my
sql
```
sql
select
day
,
sum
(
amount
)
from
view_daily_payment
where
day
between
$
1
and
date
(
'yesterday'
)
...
...
data/3.MySQL高阶/5.运维与架构/6.复制过滤器/filter.md
浏览文件 @
ff78e9ab
...
...
@@ -19,7 +19,7 @@
可以在主库中执行以下命令设定只复制 goods 数据库和 auth 数据库
```
my
sql
```
sql
SET
GLOBAL
binlog
-
do
-
db
=
goods
,
auth
;
```
...
...
@@ -35,7 +35,7 @@ binlog-do-db=goods,auth
可以在从库执行以下命令,设定只复制 goods 数据库和 auth 数据库
```
my
sql
```
sql
SET
GLOBAL
replicate
-
do
-
db
=
goods
,
auth
;
```
...
...
@@ -43,7 +43,7 @@ SET GLOBAL replicate-do-db=goods,auth;
可以在从库执行以下命令,设定只复制 goods 数据库和 auth 数据库
```
my
sql
```
sql
CHANGE
REPLICATION
FILTER
REPLICATE
-
DO
-
DB
=
(
goods
,
order
);
```
...
...
@@ -59,7 +59,7 @@ replicate-do-db=goods,order;
可以在主库中执行以下命令设定忽略 goods 数据库和 auth 数据库
```
my
sql
```
sql
SET
GLOBAL
binlog
-
ignore
-
db
=
goods
,
auth
;
```
...
...
@@ -75,7 +75,7 @@ binlog-ignore-db=goods,auth
可以在从库执行以下命令,设定忽略 goods 数据库和 auth 数据库
```
my
sql
```
sql
SET
GLOBAL
replicate
-
ignore
-
db
=
goods
,
auth
;
```
...
...
@@ -83,7 +83,7 @@ SET GLOBAL replicate-ignore-db=goods,auth;
可以在从库执行以下命令,设定忽略 goods 数据库和 auth 数据库
```
my
sql
```
sql
CHANGE
REPLICATION
FILTER
REPLICATE_IGNORE_DB
=
(
goods
,
auth
);
```
...
...
@@ -99,7 +99,7 @@ replicate-ignore-db=goods,order;
可以在在从库的 MySQL 命令行设定只同步 goods 表和 orders 表
```
my
sql
```
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 表
```
my
sql
```
sql
CHANGE
REPLICATION
FILTER
REPLICATE_DO_TABLE
=
(
goods
.
goods
,
goods
.
orders
);
```
...
...
@@ -123,7 +123,7 @@ replicate-do-table=goods.goods,goods.orders
可以在在从库的 MySQL 命令行设定只同步名称前缀为
`t_`
的表
```
my
sql
```
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 表
```
my
sql
```
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 表
```
my
sql
```
sql
CHANGE
REPLICATION
FILTER
REPLICATE_
IGNORE_TABLE
=
(
goods
.
orders
,
goods
.
trade
);
```
...
...
@@ -156,7 +156,7 @@ replicate-ignore-table =goods.orders,goods.trade
可以在在从库的 MySQL 命令行设定忽略名称前缀为
`o_`
的表
```
my
sql
```
sql
CHANGE
REPLICATION
FILTER
REPLICATE_WILD_DO_TABLE
=
(
goods
.
o_
%
);
```
...
...
@@ -164,6 +164,6 @@ CHANGE REPLICATION FILTER REPLICATE_WILD_DO_TABLE =( goods.o_%);
设定过滤器时,可以指定通道,例如
```
my
sql
```
sql
CHANGE
REPLICATION
FILTER
REPLICATE
-
DO
-
DB
=
(
goods
,
auth
)
FOR
CHANNEL
‘
channel
-
name
’
;
```
\ No newline at end of file
data/3.MySQL高阶/6.查询优化/1. SHOW STATUS/show_status.md
浏览文件 @
ff78e9ab
...
...
@@ -11,7 +11,7 @@ Goods 数据库近期在每日高峰时段很慢,Joe 想初步的查看一下
## 答案
```
my
sql
```
sql
show
global
status
;
```
...
...
@@ -19,19 +19,19 @@ show global status;
### A
```
my
sql
```
sql
show
status
;
```
### B
```
my
sql
```
sql
show
session
status
;
```
### C
```
my
sql
```
sql
show
local
status
;
```
data/3.MySQL高阶/6.查询优化/3. EXPLAIN/explain.md
浏览文件 @
ff78e9ab
...
...
@@ -2,7 +2,7 @@
Joe 从交易服务中发现了一些高频查询和慢查询,例如
```
my
sql
```
sql
with
recursive
r
(
id
)
as
(
select
id
from
orders
where
id
=
$
1
...
...
@@ -28,7 +28,7 @@ from orders
在测试库使用
```
my
sql
```
sql
explain
with
recursive
r
(
id
)
as
(
select
id
from
orders
where
id
=
$
1
...
...
@@ -43,7 +43,7 @@ from orders
进行剖分,对于需要了解详细执行计划的使用
```
my
sql
```
sql
explain
analyze
with
recursive
r
(
id
)
as
(
select
id
from
orders
where
id
=
100
...
...
@@ -72,7 +72,7 @@ from orders
使用
```
my
sql
```
sql
analyze
with
recursive
r
(
id
)
as
(
select
id
from
orders
where
id
=
100
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录