提交 68af5052 编写于 作者: M Mars Liu

add window function excerise

上级 92a0b9a1
{
"type": "code_options",
"author": "ccat",
"source": "datetime.md",
"notebook_enable": false,
"exercise_id": "89e67a85e4144bea88aded6e4dd280c2"
}
\ No newline at end of file
# 时间默认值
Joe 写了一个订单表的创建语句:
```postgresql
create table orders (
id serial primary key,
item_id int,
amount int,
unit_price money,
price money
);
```
现在,Joe 需要给这个表加入下单时间,即订单写入数据库的时间,那么他应该将这个语句修改为:
## 答案
```postgresql
create table orders (
id serial primary key,
item_id int,
amount int,
unit_price money,
price money,
ts timestamp default now()
);
```
## 选项
### A
```postgresql
create table orders (
id serial primary key,
item_id int,
amount int,
unit_price money,
price money,
ts varchar(16) default now()
);
```
### B
```postgresql
create table orders (
id serial primary key,
item_id int,
amount int,
unit_price money,
price money,
ts varchar(16) format 'yyyy-mm-dd'
);
```
### C
```postgresql
create table orders (
id serial primary key,
item_id int,
amount int,
unit_price money,
price money,
ts date default now()
);
```
### D
```postgresql
create table orders (
id serial primary key,
item_id int,
amount int,
unit_price money,
price money,
ts datetime default now()
);
```
{
"type": "code_options",
"author": "ccat",
"source": "description.md",
"notebook_enable": false,
"exercise_id": "deb54053952b41b894e244277a9c1acf"
}
\ No newline at end of file
# 文本字段
Joe 在设计订单表,他已经完成了下列内容:
```postgresql
create table orders (
id serial primary key,
item_id int,
amount int,
unit_price money,
price money,
ts timestamp default now()
);
```
现在他需要给订单表加入一个 description 字段,这个字段需要保存订单的文字说明,这些文本不会超过两千字节, Joe 应该把建表语句修改为:
## 答案
```postgresql
create table orders (
id serial primary key,
item_id int,
amount int,
unit_price money,
price money,
description text,
ts timestamp default now()
);
```
## 选项
### A
```postgresql
create table orders (
id serial primary key,
item_id int,
amount int,
unit_price money,
price money,
description char(2000),
ts timestamp default now()
);
```
### B
```postgresql
create table orders (
id serial primary key,
item_id int,
amount int,
unit_price money,
price money,
description varchar(256) default '',
ts timestamp default now()
);
```
### C
```postgresql
create table orders (
id serial primary key,
item_id int,
amount int,
unit_price money,
price money,
description text(2000),
ts timestamp default now()
);
```
### D
```postgresql
create table orders (
id serial primary key,
item_id int,
amount int,
unit_price money,
price money,
description tinytext(2000),
ts timestamp default now()
);
```
\ No newline at end of file
# 数值的隐式类型转换
Joe 需要使用下列表做一项数值计算
```postgresql
create table points(
id serial primary key,
x int,
y int
);
```
计算查询为:
```postgresql
select id, (x^2 + y^2)/2 as result from points;
```
得到的结果集中,result 列的类型应该是:
## 答案
double
## 选项
### A
float
### B
decimal
### C
int
### D
long
### E
byte
{ {
"keywords": [ "keywords": [
"函数", "window function"
"function"
], ],
"children": [], "children": [],
"node_id": "pg-cab66a558cda467eabd9587b5a8257bd", "node_id": "pg-cab66a558cda467eabd9587b5a8257bd",
"export": [ "export": [
"salary.json" "salary.json",
"distribute.json"
], ],
"keywords_must": [ "keywords_must": [
"函数", "window function"
"function",
"window"
], ],
"keywords_forbid": [] "keywords_forbid": []
} }
\ No newline at end of file
{
"type": "code_options",
"author": "ccat",
"source": "distribute.md",
"notebook_enable": false,
"exercise_id": "9b4da19d895e4761a8946b0922693e38"
}
\ No newline at end of file
# 分布函数
关于分布函数,以下说法正确的是
1. `PERCENT_RANK()`函数是等级值百分比函数。
2. `CUME_DIST()`函数主要用于查询小于或等于某个值的比例
(number of partition rows preceding or peers with current row) / (total partition rows)
3. `PERCENT_RANK() `按照 ` (rank - 1) / (total partition rows - 1)` 计算, 其中,
rank 的值为使用RANK()函数产生的序号,rows的值为当前窗口的总记录数。
## 答案
全部都对
## 选项
### A
```
1, 2
```
### B
```
2, 3
```
### C
全都不对
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
"depends": [], "depends": [],
"type": "qa_task", "type": "qa_task",
"task_link": "https://ask.csdn.net/channel/20/tag/300001", "task_link": "https://ask.csdn.net/channel/20/tag/300001",
"task_info":{ "task_info": {
"tag_name": "数据库" "tag_name": "数据库"
}, },
"notebook_enable": false, "notebook_enable": false,
......
...@@ -29,8 +29,7 @@ ...@@ -29,8 +29,7 @@
"relational", "relational",
"rdbms" "rdbms"
], ],
"keywords_forbid": [], "keywords_forbid": []
"group": 0
} }
}, },
{ {
...@@ -47,14 +46,12 @@ ...@@ -47,14 +46,12 @@
"服务器", "服务器",
"客户端" "客户端"
], ],
"keywords_forbid": [], "keywords_forbid": []
"group": 0
} }
} }
], ],
"keywords_must": [], "keywords_must": [],
"keywords_forbid": [], "keywords_forbid": []
"group": 0
} }
}, },
{ {
...@@ -73,8 +70,7 @@ ...@@ -73,8 +70,7 @@
"keywords_must": [ "keywords_must": [
"安装" "安装"
], ],
"keywords_forbid": [], "keywords_forbid": []
"group": 0
} }
}, },
{ {
...@@ -89,8 +85,7 @@ ...@@ -89,8 +85,7 @@
"keywords_must": [ "keywords_must": [
"登录" "登录"
], ],
"keywords_forbid": [], "keywords_forbid": []
"group": 0
} }
}, },
{ {
...@@ -106,14 +101,12 @@ ...@@ -106,14 +101,12 @@
"基本用法", "基本用法",
"入门" "入门"
], ],
"keywords_forbid": [], "keywords_forbid": []
"group": 0
} }
} }
], ],
"keywords_must": [], "keywords_must": [],
"keywords_forbid": [], "keywords_forbid": []
"group": 0
} }
}, },
{ {
...@@ -133,8 +126,7 @@ ...@@ -133,8 +126,7 @@
"keywords_must": [ "keywords_must": [
"psql" "psql"
], ],
"keywords_forbid": [], "keywords_forbid": []
"group": 0
} }
}, },
{ {
...@@ -149,8 +141,7 @@ ...@@ -149,8 +141,7 @@
"语法", "语法",
"SQL" "SQL"
], ],
"keywords_forbid": [], "keywords_forbid": []
"group": 0
} }
}, },
{ {
...@@ -170,20 +161,35 @@ ...@@ -170,20 +161,35 @@
"update", "update",
"delete" "delete"
], ],
"keywords_forbid": [], "keywords_forbid": []
"group": 0 }
},
{
"常见数据类型": {
"node_id": "pg-3c400d541e81472e842be3355978c33a",
"keywords": [
"datetime",
"text",
"varchar",
"int",
"double",
"float",
"decimal",
"timestamp"
],
"children": [],
"keywords_must": [],
"keywords_forbid": []
} }
} }
], ],
"keywords_must": [], "keywords_must": [],
"keywords_forbid": [], "keywords_forbid": []
"group": 0
} }
} }
], ],
"keywords_must": [], "keywords_must": [],
"keywords_forbid": [], "keywords_forbid": []
"group": 0
} }
}, },
{ {
...@@ -208,8 +214,7 @@ ...@@ -208,8 +214,7 @@
"表", "表",
"table" "table"
], ],
"keywords_forbid": [], "keywords_forbid": []
"group": 0
} }
}, },
{ {
...@@ -224,8 +229,7 @@ ...@@ -224,8 +229,7 @@
"函数", "函数",
"function" "function"
], ],
"keywords_forbid": [], "keywords_forbid": []
"group": 0
} }
}, },
{ {
...@@ -250,8 +254,7 @@ ...@@ -250,8 +254,7 @@
"权限", "权限",
"privilege" "privilege"
], ],
"keywords_forbid": [], "keywords_forbid": []
"group": 0
} }
}, },
{ {
...@@ -270,8 +273,7 @@ ...@@ -270,8 +273,7 @@
"constraints", "constraints",
"index" "index"
], ],
"keywords_forbid": [], "keywords_forbid": []
"group": 0
} }
}, },
{ {
...@@ -286,8 +288,7 @@ ...@@ -286,8 +288,7 @@
"trigger", "trigger",
"触发器" "触发器"
], ],
"keywords_forbid": [], "keywords_forbid": []
"group": 0
} }
}, },
{ {
...@@ -303,14 +304,12 @@ ...@@ -303,14 +304,12 @@
"数据库扩展", "数据库扩展",
"extension" "extension"
], ],
"keywords_forbid": [], "keywords_forbid": []
"group": 0
} }
} }
], ],
"keywords_must": [], "keywords_must": [],
"keywords_forbid": [], "keywords_forbid": []
"group": 0
} }
}, },
{ {
...@@ -331,8 +330,7 @@ ...@@ -331,8 +330,7 @@
"分组", "分组",
"聚合" "聚合"
], ],
"keywords_forbid": [], "keywords_forbid": []
"group": 0
} }
}, },
{ {
...@@ -347,8 +345,7 @@ ...@@ -347,8 +345,7 @@
"join", "join",
"连接查询" "连接查询"
], ],
"keywords_forbid": [], "keywords_forbid": []
"group": 0
} }
}, },
{ {
...@@ -363,8 +360,7 @@ ...@@ -363,8 +360,7 @@
"子查询", "子查询",
"subquery" "subquery"
], ],
"keywords_forbid": [], "keywords_forbid": []
"group": 0
} }
}, },
{ {
...@@ -381,8 +377,7 @@ ...@@ -381,8 +377,7 @@
"limit", "limit",
"offset" "offset"
], ],
"keywords_forbid": [], "keywords_forbid": []
"group": 0
} }
}, },
{ {
...@@ -397,8 +392,7 @@ ...@@ -397,8 +392,7 @@
"keywords_must": [ "keywords_must": [
"cte" "cte"
], ],
"keywords_forbid": [], "keywords_forbid": []
"group": 0
} }
}, },
{ {
...@@ -412,8 +406,7 @@ ...@@ -412,8 +406,7 @@
"keywords_must": [ "keywords_must": [
"过程化" "过程化"
], ],
"keywords_forbid": [], "keywords_forbid": []
"group": 0
} }
}, },
{ {
...@@ -430,20 +423,17 @@ ...@@ -430,20 +423,17 @@
"授权", "授权",
"ddl" "ddl"
], ],
"keywords_forbid": [], "keywords_forbid": []
"group": 0
} }
} }
], ],
"keywords_must": [], "keywords_must": [],
"keywords_forbid": [], "keywords_forbid": []
"group": 0
} }
} }
], ],
"keywords_must": [], "keywords_must": [],
"keywords_forbid": [], "keywords_forbid": []
"group": 0
} }
}, },
{ {
...@@ -469,8 +459,7 @@ ...@@ -469,8 +459,7 @@
"keywords_must": [ "keywords_must": [
"standby" "standby"
], ],
"keywords_forbid": [], "keywords_forbid": []
"group": 0
} }
}, },
{ {
...@@ -487,8 +476,7 @@ ...@@ -487,8 +476,7 @@
"流式复制", "流式复制",
"流复制" "流复制"
], ],
"keywords_forbid": [], "keywords_forbid": []
"group": 0
} }
}, },
{ {
...@@ -503,14 +491,12 @@ ...@@ -503,14 +491,12 @@
"外部数据连接", "外部数据连接",
"fdw" "fdw"
], ],
"keywords_forbid": [], "keywords_forbid": []
"group": 0
} }
} }
], ],
"keywords_must": [], "keywords_must": [],
"keywords_forbid": [], "keywords_forbid": []
"group": 0
} }
}, },
{ {
...@@ -530,8 +516,7 @@ ...@@ -530,8 +516,7 @@
"gis", "gis",
"几何" "几何"
], ],
"keywords_forbid": [], "keywords_forbid": []
"group": 0
} }
}, },
{ {
...@@ -546,8 +531,7 @@ ...@@ -546,8 +531,7 @@
"json", "json",
"jsonb" "jsonb"
], ],
"keywords_forbid": [], "keywords_forbid": []
"group": 0
} }
}, },
{ {
...@@ -569,8 +553,7 @@ ...@@ -569,8 +553,7 @@
], ],
"" ""
], ],
"keywords_forbid": [], "keywords_forbid": []
"group": 0
} }
}, },
{ {
...@@ -585,14 +568,12 @@ ...@@ -585,14 +568,12 @@
"视图", "视图",
"view" "view"
], ],
"keywords_forbid": [], "keywords_forbid": []
"group": 0
} }
} }
], ],
"keywords_must": [], "keywords_must": [],
"keywords_forbid": [], "keywords_forbid": []
"group": 0
} }
}, },
{ {
...@@ -614,25 +595,20 @@ ...@@ -614,25 +595,20 @@
"递归查询", "递归查询",
"recursive" "recursive"
], ],
"keywords_forbid": [], "keywords_forbid": []
"group": 0
} }
}, },
{ {
"Window Function": { "Window Function": {
"node_id": "pg-cab66a558cda467eabd9587b5a8257bd", "node_id": "pg-cab66a558cda467eabd9587b5a8257bd",
"keywords": [ "keywords": [
"函数", "window function"
"function"
], ],
"children": [], "children": [],
"keywords_must": [ "keywords_must": [
"函数", "window function"
"function",
"window"
], ],
"keywords_forbid": [], "keywords_forbid": []
"group": 0
} }
}, },
{ {
...@@ -649,8 +625,7 @@ ...@@ -649,8 +625,7 @@
"交叉透视表", "交叉透视表",
"pivot" "pivot"
], ],
"keywords_forbid": [], "keywords_forbid": []
"group": 0
} }
}, },
{ {
...@@ -666,8 +641,7 @@ ...@@ -666,8 +641,7 @@
"conflict", "conflict",
"冲突" "冲突"
], ],
"keywords_forbid": [], "keywords_forbid": []
"group": 0
} }
}, },
{ {
...@@ -682,8 +656,7 @@ ...@@ -682,8 +656,7 @@
"事务", "事务",
"transaction" "transaction"
], ],
"keywords_forbid": [], "keywords_forbid": []
"group": 0
} }
}, },
{ {
...@@ -702,14 +675,12 @@ ...@@ -702,14 +675,12 @@
"performance", "performance",
"优化" "优化"
], ],
"keywords_forbid": [], "keywords_forbid": []
"group": 0
} }
} }
], ],
"keywords_must": [], "keywords_must": [],
"keywords_forbid": [], "keywords_forbid": []
"group": 0
} }
}, },
{ {
...@@ -727,25 +698,21 @@ ...@@ -727,25 +698,21 @@
"keywords_must": [ "keywords_must": [
"数据库问答" "数据库问答"
], ],
"keywords_forbid": [], "keywords_forbid": []
"group": 0
} }
} }
], ],
"keywords_must": [], "keywords_must": [],
"keywords_forbid": [], "keywords_forbid": []
"group": 0
} }
} }
], ],
"keywords_must": [], "keywords_must": [],
"keywords_forbid": [], "keywords_forbid": []
"group": 0
} }
} }
], ],
"keywords_must": [], "keywords_must": [],
"keywords_forbid": [], "keywords_forbid": []
"group": 0
} }
} }
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册