Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
CSDN 技术社区
skill_tree_mysql
提交
3e4651af
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看板
提交
3e4651af
编写于
5月 25, 2022
作者:
M
Mars Liu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
having
上级
1b5a3d67
变更
43
隐藏空白更改
内联
并排
Showing
43 changed file
with
607 addition
and
145 deletion
+607
-145
data/2.MySQL中阶/1.数据库组成/1.用户和权限/grant.md
data/2.MySQL中阶/1.数据库组成/1.用户和权限/grant.md
+13
-13
data/2.MySQL中阶/1.数据库组成/1.用户和权限/revoke.md
data/2.MySQL中阶/1.数据库组成/1.用户和权限/revoke.md
+4
-4
data/2.MySQL中阶/1.数据库组成/1.用户和权限/role.md
data/2.MySQL中阶/1.数据库组成/1.用户和权限/role.md
+16
-12
data/2.MySQL中阶/1.数据库组成/2.表/auto_increment.json
data/2.MySQL中阶/1.数据库组成/2.表/auto_increment.json
+2
-1
data/2.MySQL中阶/1.数据库组成/2.表/auto_increment.md
data/2.MySQL中阶/1.数据库组成/2.表/auto_increment.md
+22
-0
data/2.MySQL中阶/1.数据库组成/2.表/config.json
data/2.MySQL中阶/1.数据库组成/2.表/config.json
+1
-1
data/2.MySQL中阶/1.数据库组成/2.表/create_table.md
data/2.MySQL中阶/1.数据库组成/2.表/create_table.md
+11
-10
data/2.MySQL中阶/1.数据库组成/2.表/serial.md
data/2.MySQL中阶/1.数据库组成/2.表/serial.md
+0
-25
data/2.MySQL中阶/1.数据库组成/3.视图/config.json
data/2.MySQL中阶/1.数据库组成/3.视图/config.json
+6
-2
data/2.MySQL中阶/1.数据库组成/3.视图/view.json
data/2.MySQL中阶/1.数据库组成/3.视图/view.json
+3
-2
data/2.MySQL中阶/1.数据库组成/3.视图/view.md
data/2.MySQL中阶/1.数据库组成/3.视图/view.md
+72
-0
data/2.MySQL中阶/1.数据库组成/4.存储过程和函数/config.json
data/2.MySQL中阶/1.数据库组成/4.存储过程和函数/config.json
+6
-9
data/2.MySQL中阶/1.数据库组成/4.存储过程和函数/function.md
data/2.MySQL中阶/1.数据库组成/4.存储过程和函数/function.md
+0
-29
data/2.MySQL中阶/1.数据库组成/4.存储过程和函数/node.txt
data/2.MySQL中阶/1.数据库组成/4.存储过程和函数/node.txt
+0
-2
data/2.MySQL中阶/1.数据库组成/5.索引和约束/primary_key.md
data/2.MySQL中阶/1.数据库组成/5.索引和约束/primary_key.md
+1
-1
data/2.MySQL中阶/1.数据库组成/5.索引和约束/unique.md
data/2.MySQL中阶/1.数据库组成/5.索引和约束/unique.md
+4
-5
data/2.MySQL中阶/1.数据库组成/5.索引和约束/unique_2.md
data/2.MySQL中阶/1.数据库组成/5.索引和约束/unique_2.md
+3
-4
data/2.MySQL中阶/2. 查询/1. 别名/aliases.json
data/2.MySQL中阶/2. 查询/1. 别名/aliases.json
+8
-0
data/2.MySQL中阶/2. 查询/1. 别名/aliases.md
data/2.MySQL中阶/2. 查询/1. 别名/aliases.md
+43
-0
data/2.MySQL中阶/2. 查询/1. 别名/config.json
data/2.MySQL中阶/2. 查询/1. 别名/config.json
+3
-1
data/2.MySQL中阶/2. 查询/2. WHERE/between.json
data/2.MySQL中阶/2. 查询/2. WHERE/between.json
+8
-0
data/2.MySQL中阶/2. 查询/2. WHERE/between.md
data/2.MySQL中阶/2. 查询/2. WHERE/between.md
+43
-0
data/2.MySQL中阶/2. 查询/2. WHERE/config.json
data/2.MySQL中阶/2. 查询/2. WHERE/config.json
+3
-1
data/2.MySQL中阶/2. 查询/3.CASE/config.json
data/2.MySQL中阶/2. 查询/3.CASE/config.json
+4
-2
data/2.MySQL中阶/2. 查询/3.CASE/pivot.json
data/2.MySQL中阶/2. 查询/3.CASE/pivot.json
+8
-0
data/2.MySQL中阶/2. 查询/3.CASE/pivot.md
data/2.MySQL中阶/2. 查询/3.CASE/pivot.md
+90
-0
data/2.MySQL中阶/2. 查询/4.DISTINCT/config.json
data/2.MySQL中阶/2. 查询/4.DISTINCT/config.json
+6
-2
data/2.MySQL中阶/2. 查询/4.DISTINCT/distinct.json
data/2.MySQL中阶/2. 查询/4.DISTINCT/distinct.json
+8
-0
data/2.MySQL中阶/2. 查询/4.DISTINCT/distinct.md
data/2.MySQL中阶/2. 查询/4.DISTINCT/distinct.md
+49
-0
data/2.MySQL中阶/2. 查询/5.ORDER BY/config.json
data/2.MySQL中阶/2. 查询/5.ORDER BY/config.json
+3
-1
data/2.MySQL中阶/2. 查询/5.ORDER BY/order_by.json
data/2.MySQL中阶/2. 查询/5.ORDER BY/order_by.json
+8
-0
data/2.MySQL中阶/2. 查询/5.ORDER BY/order_by.md
data/2.MySQL中阶/2. 查询/5.ORDER BY/order_by.md
+52
-0
data/2.MySQL中阶/2. 查询/8. 分页查询/paged.json
data/2.MySQL中阶/2. 查询/8. 分页查询/paged.json
+2
-1
data/2.MySQL中阶/2. 查询/8. 分页查询/paged.md
data/2.MySQL中阶/2. 查询/8. 分页查询/paged.md
+5
-5
data/2.MySQL中阶/3.聚合和分组/6.HAVING/config.json
data/2.MySQL中阶/3.聚合和分组/6.HAVING/config.json
+3
-1
data/2.MySQL中阶/3.聚合和分组/6.HAVING/having.json
data/2.MySQL中阶/3.聚合和分组/6.HAVING/having.json
+8
-0
data/2.MySQL中阶/3.聚合和分组/6.HAVING/having.md
data/2.MySQL中阶/3.聚合和分组/6.HAVING/having.md
+49
-0
data/2.MySQL中阶/4.连接查询/5. 复杂连接/config.json
data/2.MySQL中阶/4.连接查询/5. 复杂连接/config.json
+3
-1
data/2.MySQL中阶/4.连接查询/5. 复杂连接/salary.json
data/2.MySQL中阶/4.连接查询/5. 复杂连接/salary.json
+0
-0
data/2.MySQL中阶/4.连接查询/5. 复杂连接/salary.md
data/2.MySQL中阶/4.连接查询/5. 复杂连接/salary.md
+0
-0
data/tree.json
data/tree.json
+23
-10
gears/sql/employee.sql
gears/sql/employee.sql
+7
-0
gears/sql/sales.sql
gears/sql/sales.sql
+7
-0
未找到文件。
data/2.MySQL中阶/1.数据库组成/1.用户和权限/grant.md
浏览文件 @
3e4651af
# 授权
# 授权
管理员要给用户
fred
授权,允许他查询 emplyee 表,应用哪一条语句?
管理员要给用户
joe
授权,允许他查询 emplyee 表,应用哪一条语句?
## 答案
## 答案
```
postgre
sql
```
my
sql
grant select on table employee to
fred
;
grant select on table employee to
joe
;
```
```
## 选项
## 选项
### 权限名错误
### 权限名错误
```
postgre
sql
```
my
sql
grant query on table employee to
fred;```
grant query on table employee to
joe;
```
```
### 权限名错误
### 权限名错误
```
postgre
sql
```
my
sql
grant read on table employee to
fred;```
grant read on table employee to
joe;
```
```
### 操作关键词错误
### 操作关键词错误
```
postgre
sql
```
my
sql
grant select on table employee of
fred;```
grant select on table employee of
joe;
```
```
### 操作错误
### 操作错误
```
postgre
sql
```
my
sql
grant select on table employee.* of
fred;```
grant select on table employee.* of
joe;
```
```
### 权限过高
### 权限过高
```
postgre
sql
```
my
sql
grant all on table employee to
fred;```
grant all on table employee to
joe;
```
```
data/2.MySQL中阶/1.数据库组成/1.用户和权限/revoke.md
浏览文件 @
3e4651af
...
@@ -5,7 +5,7 @@
...
@@ -5,7 +5,7 @@
## 答案
## 答案
```
postgre
sql
```
my
sql
revoke select on trade from fred;
revoke select on trade from fred;
```
```
...
@@ -13,19 +13,19 @@ revoke select on trade from fred;
...
@@ -13,19 +13,19 @@ revoke select on trade from fred;
### 操作错误
### 操作错误
```
postgre
sql
```
my
sql
grant not select on trade to fred;
grant not select on trade to fred;
```
```
### 操作关键字错误
### 操作关键字错误
```
postgre
sql
```
my
sql
revoke select on trade to fred;
revoke select on trade to fred;
```
```
### 指定权限错误
### 指定权限错误
```
postgre
sql
```
my
sql
revoke owned trade from fred;
revoke owned trade from fred;
```
```
...
...
data/2.MySQL中阶/1.数据库组成/1.用户和权限/role.md
浏览文件 @
3e4651af
# 角色
# 角色
你是 rental dvd 公司的数据库管理员,公司数据分析组有 Fred、Alice、James、Jone 四位成员,现在你
需要给数据分析组授权,允许他们
Joe 现在是团队的 DBA,公司数据分析组有 Fred、Alice、James、Jone 四位成员,现在Joe
需要给数据分析组授权,允许他们
查询
trade 数据库的 public schema 中的所有表,规范
的操作应该是
查询
goods 数据库中的所有表,
*规范*
的操作应该是
## 答案
## 答案
```
postgre
sql
```
my
sql
create role analysis;
create role analysis;
grant analysis to fred, alice, james, jone;
grant analysis to fred, alice, james, jone;
grant select on all tables in schema public to analysis;
grant select on goods.* to analysis;
flush privileges;
```
```
## 选项
## 选项
### 将来人员变动管理会很繁琐
### 将来人员变动管理会很繁琐
```
postgre
sql
```
my
sql
grant select on
all tables in schema public
to fred, alice, james, jone;
grant select on
goods.*
to fred, alice, james, jone;
```
```
###
过度授权
###
错误的语法
```
postgre
sql
```
my
sql
create role analysis;
create role analysis;
grant analysis to fred, alice, james, jone;
grant analysis to fred, alice, james, jone;
grant all on all tables in schema public to analysis;
grant all on all tables in schema goods to analysis;
flush privileges;
```
```
###
语句不完整
###
过度授权
```
postgre
sql
```
my
sql
create role analysis;
create role analysis;
grant analysis to fred, alice, james, jone;
grant analysis to fred, alice, james, jone;
grant select on all to analysis;
grant select on *.* to analysis;
flush privileges ;
```
```
\ No newline at end of file
data/2.MySQL中阶/1.数据库组成/2.表/
serial
.json
→
data/2.MySQL中阶/1.数据库组成/2.表/
auto_increment
.json
浏览文件 @
3e4651af
{
{
"type"
:
"code_options"
,
"type"
:
"code_options"
,
"author"
:
"ccat"
,
"author"
:
"ccat"
,
"source"
:
"
serial
.md"
,
"source"
:
"
auto_increment
.md"
,
"notebook_enable"
:
false
,
"notebook_enable"
:
false
,
"exercise_id"
:
"ac5111c4826b48659e6ba60aa614706d"
"exercise_id"
:
"ac5111c4826b48659e6ba60aa614706d"
}
}
\ No newline at end of file
data/2.MySQL中阶/1.数据库组成/2.表/auto_increment.md
0 → 100644
浏览文件 @
3e4651af
# 自增序列
关于 MySQL 的自增字段,错误的说法是
## 答案
自增字段必须名为 id。
## 选项
### 自增字段只能主键,每个表至多只能有一个
自增字段必须是主键。
### B
插入操作失败,自增计数仍然会被递增,下次操作使用下一个整数。
### C
自增字段默认从 1 开始。
data/2.MySQL中阶/1.数据库组成/2.表/config.json
浏览文件 @
3e4651af
...
@@ -8,7 +8,7 @@
...
@@ -8,7 +8,7 @@
"export"
:
[
"export"
:
[
"table.json"
,
"table.json"
,
"create_table.json"
,
"create_table.json"
,
"
serial
.json"
"
auto_increment
.json"
],
],
"keywords_must"
:
[
"keywords_must"
:
[
"表"
,
"表"
,
...
...
data/2.MySQL中阶/1.数据库组成/2.表/create_table.md
浏览文件 @
3e4651af
# 建表语句
# 建表语句
现在
我们尝试
建立一个简化的交易流水表 trade,需要一个自增主键,一个content字段保存订单详情,,
现在
Joe 需要
建立一个简化的交易流水表 trade,需要一个自增主键,一个content字段保存订单详情,,
需要有一个时间戳字段记录订单入库时间,那么哪一个语句是对的?
需要有一个时间戳字段记录订单入库时间,那么哪一个语句是对的?
## 答案
## 答案
```
postgre
sql
```
my
sql
create table trade (
create table trade (
id
serial primary key
,
id
int primary key auto_increment
,
content
text
,
content
varchar(8000)
,
created_at timestamp default now()
created_at timestamp default now()
);
);
```
```
...
@@ -17,30 +17,30 @@ create table trade (
...
@@ -17,30 +17,30 @@ create table trade (
### 主键没有设置自增,不符合题意
### 主键没有设置自增,不符合题意
```
postgre
sql
```
my
sql
create table trade (
create table trade (
id integer primary key,
id integer primary key,
content
text
,
content
varchar(8000)
,
created_at timestamp default now()
created_at timestamp default now()
);
);
```
```
### 时间戳没有设置默认值
### 时间戳没有设置默认值
```
postgre
sql
```
my
sql
create table trade (
create table trade (
id serial primary key,
id serial primary key,
content
text
,
content
varchar(8000)
,
created_at timestamp
created_at timestamp
);
);
```
```
### 没有主键,不符合题设
### 没有主键,不符合题设
```
postgre
sql
```
my
sql
create table trade (
create table trade (
id serial,
id serial,
content
text
,
content
varchar(8000)
,
created_at timestamp default now()
created_at timestamp default now()
);
);
```
```
\ No newline at end of file
data/2.MySQL中阶/1.数据库组成/2.表/serial.md
已删除
100644 → 0
浏览文件 @
1b5a3d67
# 自增序列
PostgreSQL 表中的自增列 serial 的底层实现机制是:
## 答案
绑定 sequence 对象的表达式默认值
## 选项
### PG采用的是独立的序列器
auto increment 计数器
### B
触发器
### C
系统表
### D
Serial 文件
data/2.MySQL中阶/1.数据库组成/3.视图/config.json
浏览文件 @
3e4651af
{
{
"node_id"
:
"mysql-98e926730d844f238dc9cd8ac5f65126"
,
"node_id"
:
"mysql-98e926730d844f238dc9cd8ac5f65126"
,
"keywords"
:
[
"view"
],
"keywords"
:
[
"view"
],
"children"
:
[],
"children"
:
[],
"export"
:
[],
"export"
:
[
"view.json"
],
"keywords_must"
:
[],
"keywords_must"
:
[],
"keywords_forbid"
:
[],
"keywords_forbid"
:
[],
"group"
:
0
"group"
:
0
...
...
data/2.MySQL中阶/1.数据库组成/
4.存储过程和函数/function
.json
→
data/2.MySQL中阶/1.数据库组成/
3.视图/view
.json
浏览文件 @
3e4651af
{
{
"type"
:
"code_options"
,
"type"
:
"code_options"
,
"author"
:
"ccat"
,
"author"
:
"ccat"
,
"source"
:
"
function
.md"
,
"source"
:
"
view
.md"
,
"notebook_enable"
:
false
,
"notebook_enable"
:
false
,
"exercise_id"
:
"
65ba04e19bad4538a4af9b3da275fe68
"
"exercise_id"
:
"
0d485e3ba6e448edbe727da0f1cf8685
"
}
}
\ No newline at end of file
data/2.MySQL中阶/1.数据库组成/3.视图/view.md
0 → 100644
浏览文件 @
3e4651af
# 视图
Joe 需要给 goods 表
```
mysql
create table goods(
id int primary key auto_increment,
category_id int,
category varchar(64),
name varchar(256),
price decimal(12, 4),
stock int,
upper_time timestamp
)
```
添加一个视图,仅展示价格超过 1000 的商品价格和名称,下列选项中正确的是:
## 答案
```
mysql
CREATE VIEW view_name_price
AS
SELECT name, price
FROM goods
WHERE price > 1000;
```
## 选项
### A
```
mysql
CREATE VIEW view_name_price
AS
SELECT name, price
FROM goods;
```
### B
```
mysql
CREATE VIEW view_name_price
AS
SELECT *
FROM goods
WHERE price > 1000;
```
### C
```
mysql
CREATE VIEW view_name_price
AS
BEGIN
SELECT name, price
FROM goods
WHERE price > 1000;
END;
```
### D
```
mysql
CREATE VIEW view_name_price
AS
BEGIN
SELECT name, price
FROM goods
WHERE price > 1000;
END;
```
data/2.MySQL中阶/1.数据库组成/4.存储过程和函数/config.json
浏览文件 @
3e4651af
{
{
"node_id"
:
"mysql-
a6b27f219f3c47c981ed1dceffa8a1a
6"
,
"node_id"
:
"mysql-
98e926730d844f238dc9cd8ac5f6512
6"
,
"keywords"
:
[
"keywords"
:
[
"函数"
,
"produce"
,
"function"
"function"
],
],
"children"
:
[],
"children"
:
[],
"export"
:
[
"export"
:
[
"function.json"
],
],
"keywords_must"
:
[
"keywords_must"
:
[],
"函数"
,
"keywords_forbid"
:
[],
"function"
"group"
:
0
],
"keywords_forbid"
:
[]
}
}
\ No newline at end of file
data/2.MySQL中阶/1.数据库组成/4.存储过程和函数/function.md
已删除
100644 → 0
浏览文件 @
1b5a3d67
# 函数
关于 PostgreSQL 函数,错误的是:
## 答案
函数必须是无副作用的
## 选项
### A
函数可以用 SQL 写,也可以用 PLPGSQL,还可以用 Python、Perl、LUA等语言。
### B
函数的参数和返回值可以是简单变量,也可以是结果集或自定义类型
### C
函数可以递归引用
### D
函数之间可以互相引用
### E
函数的使用权限可以通过 grant/revoke/deny 管理
data/2.MySQL中阶/1.数据库组成/4.存储过程和函数/node.txt
浏览文件 @
3e4651af
第十六章
\ No newline at end of file
data/2.MySQL中阶/1.数据库组成/5.索引和约束/primary_key.md
浏览文件 @
3e4651af
# 主键
# 主键
关于
Postgre
SQL 的主键,哪一项是错误的?
关于
My
SQL 的主键,哪一项是错误的?
## 答案
## 答案
...
...
data/2.MySQL中阶/1.数据库组成/5.索引和约束/unique.md
浏览文件 @
3e4651af
...
@@ -2,13 +2,12 @@
...
@@ -2,13 +2,12 @@
现有一个图书登记表:
现有一个图书登记表:
```
postgre
sql
```
my
sql
create table book(
create table book(
id
serial primary key
,
id
int primary key auto_increment
,
title text,
title text,
publish_at date,
publish_at date,
isbn text,
isbn text
meta jsonb default '{}'::jsonb
)
)
```
```
...
@@ -16,7 +15,7 @@ create table book(
...
@@ -16,7 +15,7 @@ create table book(
1.
删除id列,将isbn设置为主键
1.
删除id列,将isbn设置为主键
2.
在 isbn 列上加唯一约束
2.
在 isbn 列上加唯一约束
3.
执行
`create index on book(id, title, publish_at, isbn
, meta
)`
3.
执行
`create index on book(id, title, publish_at, isbn)`
4.
在 id 键上加唯一约束
4.
在 id 键上加唯一约束
## 答案
## 答案
...
...
data/2.MySQL中阶/1.数据库组成/5.索引和约束/unique_2.md
浏览文件 @
3e4651af
...
@@ -2,13 +2,12 @@
...
@@ -2,13 +2,12 @@
现有一个图书登记表:
现有一个图书登记表:
```
postgre
sql
```
my
sql
create table book(
create table book(
id
serial primary key
,
id
int primary key auto_increment
,
title text,
title text,
publish_at date,
publish_at date,
isbn text,
isbn text
meta jsonb default '{}'::jsonb
)
)
```
```
...
...
data/2.MySQL中阶/2. 查询/1. 别名/aliases.json
0 → 100644
浏览文件 @
3e4651af
{
"type"
:
"code_options"
,
"author"
:
"ccat"
,
"source"
:
"aliases.md"
,
"notebook_enable"
:
false
,
"exercise_id"
:
"7a6d06703d1448209e9d82074d1887fb"
}
\ No newline at end of file
data/2.MySQL中阶/2. 查询/1. 别名/aliases.md
0 → 100644
浏览文件 @
3e4651af
# 别名
关于别名,以下说法中正确的是:
1.
查询集(表或子查询)可以指定别名
2.
查询集的列可以指定别名
3.
别名只能用合法的变量名,即字母开头,只由英文数字、字母和下划线组成
4.
可以用双引号或反引号将别名包围起来
## 答案
```
1, 2, 4
```
## 选项
### A
全部都对
### B
全都不对
### C
```
2, 4
```
### D
```
2, 3, 4
```
### E
````
3, 4
````
\ No newline at end of file
data/2.MySQL中阶/2. 查询/1. 别名/config.json
浏览文件 @
3e4651af
...
@@ -2,7 +2,9 @@
...
@@ -2,7 +2,9 @@
"node_id"
:
"mysql-1d350c6226d443bdb76b5058d8ee23e7"
,
"node_id"
:
"mysql-1d350c6226d443bdb76b5058d8ee23e7"
,
"keywords"
:
[],
"keywords"
:
[],
"children"
:
[],
"children"
:
[],
"export"
:
[],
"export"
:
[
"aliases.json"
],
"keywords_must"
:
[],
"keywords_must"
:
[],
"keywords_forbid"
:
[],
"keywords_forbid"
:
[],
"group"
:
0
"group"
:
0
...
...
data/2.MySQL中阶/2. 查询/2. WHERE/between.json
0 → 100644
浏览文件 @
3e4651af
{
"type"
:
"code_options"
,
"author"
:
"ccat"
,
"source"
:
"between.md"
,
"notebook_enable"
:
false
,
"exercise_id"
:
"6ad1d6bd4fa7421890b7498b5648b4e0"
}
\ No newline at end of file
data/2.MySQL中阶/2. 查询/2. WHERE/between.md
0 → 100644
浏览文件 @
3e4651af
# Between
Joe 要查询 goods 表
```
mysql
create table goods(
id int primary key auto_increment,
category_id int,
category varchar(64),
name varchar(256),
price decimal(12, 4),
stock int,
upper_time timestamp
)
```
中价格在 1000 到 2000 之间(包含1000和2000)的数据,以下查询中错误的是:
## 答案
```
mysql
SELECT * FROM goods HAVING price BETWEEN 1000 AND 2000;
```
## 选项
### A
```
mysql
SELECT * FROM goods WHERE price BETWEEN 1000 AND 2000;
```
### B
```
mysql
SELECT * FROM goods WHERE price >= 1000 AND price <= 2000;
```
### C
```
mysql
SELECT * FROM goods WHERE not (price < 1000 or price > 2000);
```
data/2.MySQL中阶/2. 查询/2. WHERE/config.json
浏览文件 @
3e4651af
...
@@ -2,7 +2,9 @@
...
@@ -2,7 +2,9 @@
"node_id"
:
"mysql-2296dbe96d584a52bd28a3ad5f655518"
,
"node_id"
:
"mysql-2296dbe96d584a52bd28a3ad5f655518"
,
"keywords"
:
[],
"keywords"
:
[],
"children"
:
[],
"children"
:
[],
"export"
:
[],
"export"
:
[
"between.json"
],
"keywords_must"
:
[],
"keywords_must"
:
[],
"keywords_forbid"
:
[],
"keywords_forbid"
:
[],
"group"
:
0
"group"
:
0
...
...
data/2.MySQL中阶/2. 查询/3.CASE/config.json
浏览文件 @
3e4651af
{
{
"node_id"
:
"mysql-8e6cd4d5f4b446a2bc3f5402de9bd49c"
,
"node_id"
:
"mysql-8e6cd4d5f4b446a2bc3f5402de9bd49c"
,
"keywords"
:
[],
"keywords"
:
[
"case"
,
"pivot"
,
"透视表"
],
"children"
:
[],
"children"
:
[],
"export"
:
[],
"export"
:
[
"pivot.json"
],
"keywords_must"
:
[],
"keywords_must"
:
[],
"keywords_forbid"
:
[],
"keywords_forbid"
:
[],
"group"
:
0
"group"
:
0
...
...
data/2.MySQL中阶/2. 查询/3.CASE/pivot.json
0 → 100644
浏览文件 @
3e4651af
{
"type"
:
"code_options"
,
"author"
:
"ccat"
,
"source"
:
"pivot.md"
,
"notebook_enable"
:
false
,
"exercise_id"
:
"d61198987832488ab53e8a18f7337946"
}
\ No newline at end of file
data/2.MySQL中阶/2. 查询/3.CASE/pivot.md
0 → 100644
浏览文件 @
3e4651af
# 透视表
现有销售记录表
```
mysql
create table sales(
id serial primary key ,
sku_id integer not null ,
amount decimal(12, 4),
created_at timestamp default now()
);
create index idx_created_at on sales(created_at);
```
现在我们希望对这个表做一个月度的透视汇总,得到2021年每个月每种商品(sku_id)的的销售总额,每个月一列,哪一项可以实现?
## 答案
```
mysql
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,
sum(case extract(month from created_at) when 3 then amount else 0 end) as Mar,
sum(case extract(month from created_at) when 4 then amount else 0 end) as Apr,
sum(case extract(month from created_at) when 5 then amount else 0 end) as May,
sum(case extract(month from created_at) when 6 then amount else 0 end) as June,
sum(case extract(month from created_at) when 7 then amount else 0 end) as July,
sum(case extract(month from created_at) when 8 then amount else 0 end) as Aug,
sum(case extract(month from created_at) when 9 then amount else 0 end) as Sept,
sum(case extract(month from created_at) when 10 then amount else 0 end) as Oct,
sum(case extract(month from created_at) when 11 then amount else 0 end) as Nov,
sum(case extract(month from created_at) when 12 then amount else 0 end) as Dec
from sales
where created_at between '2020-01-01'::timestamp and '2021-01-01'::timestamp
group by sku_id;
```
## 选项
### 格式不相符
```
mysql
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
group by 1, 2;
```
### 计算逻辑错误
```
mysql
select sku_id,
sum(amount) as Jan,
sum(amount) as Feb,
sum(amount) as Mar,
sum(amount) as Apr,
sum(amount) as May,
sum(amount) as June,
sum(amount) as July,
sum(amount) as Aug,
sum(amount) as Sept,
sum(amount) as Oct,
sum(amount) as Nov,
sum(amount) as Dec
from sales
where created_at between '2020-01-01'::timestamp and '2021-01-01'::timestamp
group by sku_id, extract(month from created_at);
```
### 计算格式错误
```
mysql
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,
sum(amount having extract(month from created_at) = 3) as Mar,
sum(amount having extract(month from created_at) = 4) as Apr,
sum(amount having extract(month from created_at) = 5) as May,
sum(amount having extract(month from created_at) = 6) as June,
sum(amount having extract(month from created_at) = 7) as July,
sum(amount having extract(month from created_at) = 8) as Aug,
sum(amount having extract(month from created_at) = 9) as Sept,
sum(amount having extract(month from created_at) = 10) as Oct,
sum(amount having extract(month from created_at) = 11) as Nov,
sum(amount having extract(month from created_at) = 12) as Dec
from sales
where created_at between '2020-01-01'::timestamp and '2021-01-01'::timestamp
group by sku_id, extract(month from created_at);
```
\ No newline at end of file
data/2.MySQL中阶/2. 查询/4.DISTINCT/config.json
浏览文件 @
3e4651af
{
{
"node_id"
:
"mysql-153ce0dadc824af98de199f193c8c75c"
,
"node_id"
:
"mysql-153ce0dadc824af98de199f193c8c75c"
,
"keywords"
:
[
"distinct"
],
"keywords"
:
[
"distinct"
],
"children"
:
[],
"children"
:
[],
"export"
:
[],
"export"
:
[
"distinct.json"
],
"keywords_must"
:
[],
"keywords_must"
:
[],
"keywords_forbid"
:
[],
"keywords_forbid"
:
[],
"group"
:
0
"group"
:
0
...
...
data/2.MySQL中阶/2. 查询/4.DISTINCT/distinct.json
0 → 100644
浏览文件 @
3e4651af
{
"type"
:
"code_options"
,
"author"
:
"ccat"
,
"source"
:
"distinct.md"
,
"notebook_enable"
:
false
,
"exercise_id"
:
"331f369b150340f9989ccea8abfcd42f"
}
\ No newline at end of file
data/2.MySQL中阶/2. 查询/4.DISTINCT/distinct.md
0 → 100644
浏览文件 @
3e4651af
# Distinct
Joe 想统计以下 goods 表
```
mysql
create table goods(
id int primary key auto_increment,
category_id int,
category varchar(64),
name varchar(256),
price decimal(12, 4),
stock int,
upper_time timestamp
)
```
中的商品有多少种不同的价格,他应该如何写这条查询?
## 答案
```
mysql
select count(distinct price) from goods;
```
## 选项
### A
```
mysql
select count(distinct *) from goods;
```
### B
```
mysql
select distinct count(price) from goods;
```
### C
```
mysql
select count(price) from goods;
```
### D
```
mysql
select distinct price from goods;
```
data/2.MySQL中阶/2. 查询/5.ORDER BY/config.json
浏览文件 @
3e4651af
...
@@ -2,7 +2,9 @@
...
@@ -2,7 +2,9 @@
"node_id"
:
"mysql-fa20a81805b44975aed265dd058c542a"
,
"node_id"
:
"mysql-fa20a81805b44975aed265dd058c542a"
,
"keywords"
:
[],
"keywords"
:
[],
"children"
:
[],
"children"
:
[],
"export"
:
[],
"export"
:
[
"order_by.json"
],
"keywords_must"
:
[],
"keywords_must"
:
[],
"keywords_forbid"
:
[],
"keywords_forbid"
:
[],
"group"
:
0
"group"
:
0
...
...
data/2.MySQL中阶/2. 查询/5.ORDER BY/order_by.json
0 → 100644
浏览文件 @
3e4651af
{
"type"
:
"code_options"
,
"author"
:
"ccat"
,
"source"
:
"order_by.md"
,
"notebook_enable"
:
false
,
"exercise_id"
:
"68e526b5717246a190e6bb06ad3e58ac"
}
\ No newline at end of file
data/2.MySQL中阶/2. 查询/5.ORDER BY/order_by.md
0 → 100644
浏览文件 @
3e4651af
# 排序
Joe 需要根据员工表
```
mysql
create table employee
(
id serial primary key,
name varchar(256),
dept varchar(256),
salary decimal(12, 4)
);
```
生成一份报表,首先按部门名称的字典序排序,部门内部按员工工资从高到低排列,那么这个查询应该是:
## 答案
```
mysql
select id, name, dept, salary from employee order by dept, salary desc;
```
## 选项
### A
```
mysql
select id, name, dept, salary from employee order by dept, salary;
```
### B
```
mysql
select id, name, dept, salary from employee order by dept desc, salary desc;
```
### C
```
mysql
select id, name, dept, salary from employee order by dept and salary desc;
```
### D
```
mysql
select id, name, dept, salary from employee order by dept, salary, id, name;
```
### E
```
mysql
select id, name, dept, salary from employee order by dept, salary desc;
```
data/2.MySQL中阶/2. 查询/8. 分页查询/paged.json
浏览文件 @
3e4651af
...
@@ -3,5 +3,5 @@
...
@@ -3,5 +3,5 @@
"author"
:
"ccat"
,
"author"
:
"ccat"
,
"source"
:
"paged.md"
,
"source"
:
"paged.md"
,
"notebook_enable"
:
false
,
"notebook_enable"
:
false
,
"exercise_id"
:
"
68e526b5717246a190e6bb06ad3e58ac
"
"exercise_id"
:
"
b80577df526846bb8eccf638480a0170
"
}
}
\ No newline at end of file
data/2.MySQL中阶/2. 查询/8. 分页查询/paged.md
浏览文件 @
3e4651af
...
@@ -2,7 +2,7 @@
...
@@ -2,7 +2,7 @@
我们有如下订单表:
我们有如下订单表:
```
postgre
sql
```
my
sql
create table orders
create table orders
(
(
id serial primary key,
id serial primary key,
...
@@ -17,7 +17,7 @@ create table orders
...
@@ -17,7 +17,7 @@ create table orders
## 答案
## 答案
```
postgre
sql
```
my
sql
select id, product_id, order_date, quantity, customer_id
select id, product_id, order_date, quantity, customer_id
from orders
from orders
where date = $1
where date = $1
...
@@ -28,7 +28,7 @@ offset $2 limit 100;
...
@@ -28,7 +28,7 @@ offset $2 limit 100;
### 缺少 limit
### 缺少 limit
```
postgre
sql
```
my
sql
select id, product_id, order_date, quantity, customer_id
select id, product_id, order_date, quantity, customer_id
from orders
from orders
where date = $1
where date = $1
...
@@ -37,7 +37,7 @@ offset $2;
...
@@ -37,7 +37,7 @@ offset $2;
### 缺少 offset
### 缺少 offset
```
postgre
sql
```
my
sql
select id, product_id, order_date, quantity, customer_id
select id, product_id, order_date, quantity, customer_id
from orders
from orders
where date = $1;
where date = $1;
...
@@ -45,7 +45,7 @@ where date = $1;
...
@@ -45,7 +45,7 @@ where date = $1;
### 结构不对
### 结构不对
```
postgre
sql
```
my
sql
select id, product_id, order_date, quantity, customer_id
select id, product_id, order_date, quantity, customer_id
from orders
from orders
where date = $1 and
where date = $1 and
...
...
data/2.MySQL中阶/3.聚合和分组/6.HAVING/config.json
浏览文件 @
3e4651af
...
@@ -2,7 +2,9 @@
...
@@ -2,7 +2,9 @@
"node_id"
:
"mysql-3b85e53dd88146798d21b7254ad85cae"
,
"node_id"
:
"mysql-3b85e53dd88146798d21b7254ad85cae"
,
"keywords"
:
[],
"keywords"
:
[],
"children"
:
[],
"children"
:
[],
"export"
:
[],
"export"
:
[
"having.json"
],
"keywords_must"
:
[],
"keywords_must"
:
[],
"keywords_forbid"
:
[],
"keywords_forbid"
:
[],
"group"
:
0
"group"
:
0
...
...
data/2.MySQL中阶/3.聚合和分组/6.HAVING/having.json
0 → 100644
浏览文件 @
3e4651af
{
"type"
:
"code_options"
,
"author"
:
"ccat"
,
"source"
:
"having.md"
,
"notebook_enable"
:
false
,
"exercise_id"
:
"2e74213549474ee680f4b72cde1a5b45"
}
\ No newline at end of file
data/2.MySQL中阶/3.聚合和分组/6.HAVING/having.md
0 → 100644
浏览文件 @
3e4651af
# Having
Joe 要从 employee 表
```
mysql
create table employee
(
id serial primary key,
name varchar(256),
dept varchar(256),
salary decimal(12, 4)
);
```
中得到每月工资开支超过十万的部门,这个查询应该怎么写?
## 答案
```
mysql
select dept from employee group by dept having sum(salary) > 100000;
```
## 选项
### A
```
mysql
select dept from employee group by dept where sum(salary) > 100000;
```
### B
```
mysql
select dept from employee where sum(salary) > 100000 group by dept;
```
### C
```
mysql
select dept from employee where sum(salary) > 100000 order by dept;
```
### D
```
mysql
select dept from employee group by dept where sum(salary) > 100000;
```
data/2.MySQL中阶/4.连接查询/5. 复杂连接/config.json
浏览文件 @
3e4651af
...
@@ -2,7 +2,9 @@
...
@@ -2,7 +2,9 @@
"node_id"
:
"mysql-a4773004e0cf432aa7ccdf6b9490838f"
,
"node_id"
:
"mysql-a4773004e0cf432aa7ccdf6b9490838f"
,
"keywords"
:
[],
"keywords"
:
[],
"children"
:
[],
"children"
:
[],
"export"
:
[],
"export"
:
[
"salary.json"
],
"keywords_must"
:
[],
"keywords_must"
:
[],
"keywords_forbid"
:
[],
"keywords_forbid"
:
[],
"group"
:
0
"group"
:
0
...
...
data/2.MySQL中阶/
3.聚合和分组
/salary.json
→
data/2.MySQL中阶/
4.连接查询/5. 复杂连接
/salary.json
浏览文件 @
3e4651af
文件已移动
data/2.MySQL中阶/
3.聚合和分组
/salary.md
→
data/2.MySQL中阶/
4.连接查询/5. 复杂连接
/salary.md
浏览文件 @
3e4651af
文件已移动
data/tree.json
浏览文件 @
3e4651af
...
@@ -296,7 +296,10 @@
...
@@ -296,7 +296,10 @@
{
{
"mysqladmin"
:
{
"mysqladmin"
:
{
"node_id"
:
"mysql-daca74b56aca48cea2da14078b518051"
,
"node_id"
:
"mysql-daca74b56aca48cea2da14078b518051"
,
"keywords"
:
[],
"keywords"
:
[
"mysqladmin"
,
"shell"
],
"children"
:
[],
"children"
:
[],
"keywords_must"
:
[],
"keywords_must"
:
[],
"keywords_forbid"
:
[]
"keywords_forbid"
:
[]
...
@@ -305,7 +308,11 @@
...
@@ -305,7 +308,11 @@
{
{
"myisampack"
:
{
"myisampack"
:
{
"node_id"
:
"mysql-b34e3244a8ba4166bd22bc4fe5f7d8db"
,
"node_id"
:
"mysql-b34e3244a8ba4166bd22bc4fe5f7d8db"
,
"keywords"
:
[],
"keywords"
:
[
"myisampack"
,
"myisam"
,
"pack"
],
"children"
:
[],
"children"
:
[],
"keywords_must"
:
[],
"keywords_must"
:
[],
"keywords_forbid"
:
[]
"keywords_forbid"
:
[]
...
@@ -314,7 +321,11 @@
...
@@ -314,7 +321,11 @@
{
{
"mysqlbinlog"
:
{
"mysqlbinlog"
:
{
"node_id"
:
"mysql-fe9caf0e07a94efc8b7c8f2a4c683efe"
,
"node_id"
:
"mysql-fe9caf0e07a94efc8b7c8f2a4c683efe"
,
"keywords"
:
[],
"keywords"
:
[
"mysqlbinlog"
,
"binlog"
,
"二进制日志"
],
"children"
:
[],
"children"
:
[],
"keywords_must"
:
[],
"keywords_must"
:
[],
"keywords_forbid"
:
[]
"keywords_forbid"
:
[]
...
@@ -359,7 +370,12 @@
...
@@ -359,7 +370,12 @@
{
{
"mysqlimport"
:
{
"mysqlimport"
:
{
"node_id"
:
"mysql-e782e10839d843c0ad36a05ae7d0366f"
,
"node_id"
:
"mysql-e782e10839d843c0ad36a05ae7d0366f"
,
"keywords"
:
[],
"keywords"
:
[
"mysqlimport"
,
"import"
,
"restore"
,
"导入"
],
"children"
:
[],
"children"
:
[],
"keywords_must"
:
[],
"keywords_must"
:
[],
"keywords_forbid"
:
[]
"keywords_forbid"
:
[]
...
@@ -438,16 +454,13 @@
...
@@ -438,16 +454,13 @@
},
},
{
{
"存储过程和函数"
:
{
"存储过程和函数"
:
{
"node_id"
:
"mysql-
a6b27f219f3c47c981ed1dceffa8a1a
6"
,
"node_id"
:
"mysql-
98e926730d844f238dc9cd8ac5f6512
6"
,
"keywords"
:
[
"keywords"
:
[
"
函数
"
,
"
produce
"
,
"function"
"function"
],
],
"children"
:
[],
"children"
:
[],
"keywords_must"
:
[
"keywords_must"
:
[],
"函数"
,
"function"
],
"keywords_forbid"
:
[]
"keywords_forbid"
:
[]
}
}
},
},
...
...
gears/sql/employee.sql
0 → 100644
浏览文件 @
3e4651af
create
table
employee
(
id
serial
primary
key
,
name
varchar
(
256
),
dept
varchar
(
256
),
salary
decimal
(
12
,
4
)
);
\ No newline at end of file
gears/sql/sales.sql
0 → 100644
浏览文件 @
3e4651af
create
table
sales
(
id
serial
primary
key
,
sku_id
integer
not
null
,
amount
decimal
(
12
,
4
),
created_at
timestamp
default
now
()
);
create
index
idx_created_at
on
sales
(
created_at
);
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录