提交 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": [
"函数",
"function"
"window function"
],
"children": [],
"node_id": "pg-cab66a558cda467eabd9587b5a8257bd",
"export": [
"salary.json"
"salary.json",
"distribute.json"
],
"keywords_must": [
"函数",
"function",
"window"
"window function"
],
"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 @@
"depends": [],
"type": "qa_task",
"task_link": "https://ask.csdn.net/channel/20/tag/300001",
"task_info":{
"task_info": {
"tag_name": "数据库"
},
"notebook_enable": false,
......
......@@ -29,8 +29,7 @@
"relational",
"rdbms"
],
"keywords_forbid": [],
"group": 0
"keywords_forbid": []
}
},
{
......@@ -47,14 +46,12 @@
"服务器",
"客户端"
],
"keywords_forbid": [],
"group": 0
"keywords_forbid": []
}
}
],
"keywords_must": [],
"keywords_forbid": [],
"group": 0
"keywords_forbid": []
}
},
{
......@@ -73,8 +70,7 @@
"keywords_must": [
"安装"
],
"keywords_forbid": [],
"group": 0
"keywords_forbid": []
}
},
{
......@@ -89,8 +85,7 @@
"keywords_must": [
"登录"
],
"keywords_forbid": [],
"group": 0
"keywords_forbid": []
}
},
{
......@@ -106,14 +101,12 @@
"基本用法",
"入门"
],
"keywords_forbid": [],
"group": 0
"keywords_forbid": []
}
}
],
"keywords_must": [],
"keywords_forbid": [],
"group": 0
"keywords_forbid": []
}
},
{
......@@ -133,8 +126,7 @@
"keywords_must": [
"psql"
],
"keywords_forbid": [],
"group": 0
"keywords_forbid": []
}
},
{
......@@ -149,8 +141,7 @@
"语法",
"SQL"
],
"keywords_forbid": [],
"group": 0
"keywords_forbid": []
}
},
{
......@@ -170,20 +161,35 @@
"update",
"delete"
],
"keywords_forbid": [],
"group": 0
"keywords_forbid": []
}
},
{
"常见数据类型": {
"node_id": "pg-3c400d541e81472e842be3355978c33a",
"keywords": [
"datetime",
"text",
"varchar",
"int",
"double",
"float",
"decimal",
"timestamp"
],
"children": [],
"keywords_must": [],
"keywords_forbid": []
}
}
],
"keywords_must": [],
"keywords_forbid": [],
"group": 0
"keywords_forbid": []
}
}
],
"keywords_must": [],
"keywords_forbid": [],
"group": 0
"keywords_forbid": []
}
},
{
......@@ -208,8 +214,7 @@
"表",
"table"
],
"keywords_forbid": [],
"group": 0
"keywords_forbid": []
}
},
{
......@@ -224,8 +229,7 @@
"函数",
"function"
],
"keywords_forbid": [],
"group": 0
"keywords_forbid": []
}
},
{
......@@ -250,8 +254,7 @@
"权限",
"privilege"
],
"keywords_forbid": [],
"group": 0
"keywords_forbid": []
}
},
{
......@@ -270,8 +273,7 @@
"constraints",
"index"
],
"keywords_forbid": [],
"group": 0
"keywords_forbid": []
}
},
{
......@@ -286,8 +288,7 @@
"trigger",
"触发器"
],
"keywords_forbid": [],
"group": 0
"keywords_forbid": []
}
},
{
......@@ -303,14 +304,12 @@
"数据库扩展",
"extension"
],
"keywords_forbid": [],
"group": 0
"keywords_forbid": []
}
}
],
"keywords_must": [],
"keywords_forbid": [],
"group": 0
"keywords_forbid": []
}
},
{
......@@ -331,8 +330,7 @@
"分组",
"聚合"
],
"keywords_forbid": [],
"group": 0
"keywords_forbid": []
}
},
{
......@@ -347,8 +345,7 @@
"join",
"连接查询"
],
"keywords_forbid": [],
"group": 0
"keywords_forbid": []
}
},
{
......@@ -363,8 +360,7 @@
"子查询",
"subquery"
],
"keywords_forbid": [],
"group": 0
"keywords_forbid": []
}
},
{
......@@ -381,8 +377,7 @@
"limit",
"offset"
],
"keywords_forbid": [],
"group": 0
"keywords_forbid": []
}
},
{
......@@ -397,8 +392,7 @@
"keywords_must": [
"cte"
],
"keywords_forbid": [],
"group": 0
"keywords_forbid": []
}
},
{
......@@ -412,8 +406,7 @@
"keywords_must": [
"过程化"
],
"keywords_forbid": [],
"group": 0
"keywords_forbid": []
}
},
{
......@@ -430,20 +423,17 @@
"授权",
"ddl"
],
"keywords_forbid": [],
"group": 0
"keywords_forbid": []
}
}
],
"keywords_must": [],
"keywords_forbid": [],
"group": 0
"keywords_forbid": []
}
}
],
"keywords_must": [],
"keywords_forbid": [],
"group": 0
"keywords_forbid": []
}
},
{
......@@ -469,8 +459,7 @@
"keywords_must": [
"standby"
],
"keywords_forbid": [],
"group": 0
"keywords_forbid": []
}
},
{
......@@ -487,8 +476,7 @@
"流式复制",
"流复制"
],
"keywords_forbid": [],
"group": 0
"keywords_forbid": []
}
},
{
......@@ -503,14 +491,12 @@
"外部数据连接",
"fdw"
],
"keywords_forbid": [],
"group": 0
"keywords_forbid": []
}
}
],
"keywords_must": [],
"keywords_forbid": [],
"group": 0
"keywords_forbid": []
}
},
{
......@@ -530,8 +516,7 @@
"gis",
"几何"
],
"keywords_forbid": [],
"group": 0
"keywords_forbid": []
}
},
{
......@@ -546,8 +531,7 @@
"json",
"jsonb"
],
"keywords_forbid": [],
"group": 0
"keywords_forbid": []
}
},
{
......@@ -569,8 +553,7 @@
],
""
],
"keywords_forbid": [],
"group": 0
"keywords_forbid": []
}
},
{
......@@ -585,14 +568,12 @@
"视图",
"view"
],
"keywords_forbid": [],
"group": 0
"keywords_forbid": []
}
}
],
"keywords_must": [],
"keywords_forbid": [],
"group": 0
"keywords_forbid": []
}
},
{
......@@ -614,25 +595,20 @@
"递归查询",
"recursive"
],
"keywords_forbid": [],
"group": 0
"keywords_forbid": []
}
},
{
"Window Function": {
"node_id": "pg-cab66a558cda467eabd9587b5a8257bd",
"keywords": [
"函数",
"function"
"window function"
],
"children": [],
"keywords_must": [
"函数",
"function",
"window"
"window function"
],
"keywords_forbid": [],
"group": 0
"keywords_forbid": []
}
},
{
......@@ -649,8 +625,7 @@
"交叉透视表",
"pivot"
],
"keywords_forbid": [],
"group": 0
"keywords_forbid": []
}
},
{
......@@ -666,8 +641,7 @@
"conflict",
"冲突"
],
"keywords_forbid": [],
"group": 0
"keywords_forbid": []
}
},
{
......@@ -682,8 +656,7 @@
"事务",
"transaction"
],
"keywords_forbid": [],
"group": 0
"keywords_forbid": []
}
},
{
......@@ -702,14 +675,12 @@
"performance",
"优化"
],
"keywords_forbid": [],
"group": 0
"keywords_forbid": []
}
}
],
"keywords_must": [],
"keywords_forbid": [],
"group": 0
"keywords_forbid": []
}
},
{
......@@ -727,25 +698,21 @@
"keywords_must": [
"数据库问答"
],
"keywords_forbid": [],
"group": 0
"keywords_forbid": []
}
}
],
"keywords_must": [],
"keywords_forbid": [],
"group": 0
"keywords_forbid": []
}
}
],
"keywords_must": [],
"keywords_forbid": [],
"group": 0
"keywords_forbid": []
}
}
],
"keywords_must": [],
"keywords_forbid": [],
"group": 0
"keywords_forbid": []
}
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册