提交 2de7db37 编写于 作者: M Mars Liu

operator

上级 9adba7b6
......@@ -2,7 +2,9 @@
"node_id": "mysql-2eb9e9d351e848f580b70cf9e7b93280",
"keywords": [],
"children": [],
"export": [],
"export": [
"update.json"
],
"keywords_must": [],
"keywords_forbid": [],
"group": 0
......
{
"type": "code_options",
"author": "ccat",
"source": "update.md",
"notebook_enable": false,
"exercise_id": "cf4476a1954440b499c84e022ec463ea"
}
\ No newline at end of file
# 更新数据
现有 employee 表如下:
```mysql
create table employee
(
id serial primary key,
name text,
dept text,
salary money
);
```
Joe 希望修改销售部(dept 字段为 sale)员工 Dora Muk 的工资,将其增加 1000。正确的修改语句是:
## 答案
```mysql
update employee set salary = salary + 1000 where dept = 'sale' and name = 'Dora Muk';
```
## 选项
### 过滤条件不严谨
```mysql
update employee set salary = salary + 1000 where name = 'Dora Muk';
```
### 缺少过滤条件
```mysql
update employee set salary = salary + 1000;
```
### 错误的赋值语句
```mysql
update employee set salary += 1000;
```
......@@ -2,7 +2,9 @@
"node_id": "mysql-3cae643e21644d6d937d69b59014922f",
"keywords": [],
"children": [],
"export": [],
"export": [
"delete.json"
],
"keywords_must": [],
"keywords_forbid": [],
"group": 0
......
{
"type": "code_options",
"author": "ccat",
"source": "delete.md",
"notebook_enable": false,
"exercise_id": "cfdd2c9789fd4fe493541cfa8811e4c9"
}
\ No newline at end of file
# 删除
现在 orders 表结构如下:
```mysql
create table orders (
id int primary key auto_increment,
item_id int,
amount int,
unit_price decimal(12, 4),
total_price decimal(12, 4),
description varchar(2000),
ts timestamp default now(),
deal bool default false
);
```
有一个业务系统会实时的将已经成交(deal 字段为 true)的订单数据转储,现在我们仅需要一个清理 程序,将已经成 交的数据从 orders 表删除并记录被删除的数据id。下面哪个操作是对的?
## 答案
在一个独立的定时任务中执行
```mysql
delete
from orders
where deal;
```
## 选项
### A
在一个独立的定时任务中执行
```mysql
truncate orders;
```
### B
在一个独立的定时任务中执行
```mysql
delete
from orders;
```
### C
在一个独立的定时任务中执行
```mysql
drop table orders;
create table if not exists orders (
id int primary key auto_increment,
item_id int,
amount int,
unit_price decimal(12, 4),
total_price decimal(12, 4),
description varchar(2000),
ts timestamp default now(),
deal bool default false
);
```
### D
建立视图
```mysql
create view order_view as
select id, meta, content, created_at
from orders
where not deal;
```
并要求业务系统只能访问这个视图。
### E
在一个独立的定时任务中执行
```mysql
delete
from orders
where deal;
```
并记录操作前后表中的最大 id
\ No newline at end of file
{
"node_id": "mysql-f5527eae7f3148108c92ff99a6d4ed4a",
"keywords": [],
"keywords": ["查询", "select"],
"children": [],
"export": [],
"export": [
"select.json"
],
"keywords_must": [],
"keywords_forbid": [],
"group": 0
......
{
"type": "code_options",
"author": "ccat",
"source": "select.md",
"notebook_enable": false,
"exercise_id": "c873b09db60f4f93a8603a15e31d2a3a"
}
\ No newline at end of file
# 基本语法
下列 SQL 语句,哪一项不合法?
## 答案
```mysql
from test select abc;
```
## 选项
### A
```mysql
select 3.14;
```
### B
```mysql
select * from employee;
```
### C
```mysql
select * from employee where dept = 'hr';
```
### D
```mysql
select id, name, dept, salary from employee where salary > 10000;
```
### E
```mysql
select now();
```
......@@ -2,7 +2,9 @@
"node_id": "mysql-91cc9c73e58945d3ba654370a057a1c7",
"keywords": [],
"children": [],
"export": [],
"export": [
"where.json"
],
"keywords_must": [],
"keywords_forbid": [],
"group": 0
......
{
"type": "code_options",
"author": "ccat",
"source": "where.md",
"notebook_enable": false,
"exercise_id": "1407e367ecca4e159cb7777fe141e8d4"
}
\ No newline at end of file
# Where 条件
Joe 希望从 orders 表
```mysql
create table orders
(
id int primary key auto_increment,
item_id int,
amount int,
unit_price decimal(12, 4),
total_price decimal(12, 4),
description varchar(2000),
ts timestamp default now(),
deal bool default false
);
```
查询 2022 年 5 月 25 日下单的所有单价低于 20 的订单id,那么这个查询应该如何写?
## 答案
```mysql
select id
from orders
where date(ts) = '2022-05-25'
and unit_prise < 20;
```
## 选项
### A
```mysql
select id
from (select * from orders where date(ts) = '2022-05-25') as o
where unit_prise < 20;
```
### B
```mysql
select id
from orders
where date(ts) = '2022-05-25'
or unit_prise < 20;
```
### C
```mysql
select id
from orders
if date(ts) = '2022-05-25' or unit_prise < 20;
```
### D
```mysql
select id
from orders
which date(ts) = '2022-05-25'
or unit_prise < 20;
```
{
"node_id": "mysql-8f2aac71ea494f1b84372d43aa436135",
"keywords": [],
"keywords": [
"operator",
"运算符"
],
"children": [],
"export": [],
"export": [
"geo.json"
],
"keywords_must": [],
"keywords_forbid": [],
"group": 0
......
{
"type": "code_options",
"author": "ccat",
"source": "geo.md",
"notebook_enable": false,
"exercise_id": "09df5b5537d340fab861362b9123fbfd"
}
\ No newline at end of file
# 数值计算
Points 表结构如下:
```mysql
create table points(
id int primary key auto_increment,
x float,
y float
)
```
现在 Joe 想要求写一个查询,得到每个点的id和模。即 √(x^2+y^2) 。这个查询应该是:
## 答案
```mysql
select id, sqrt(x^2 + y^2) from points;
```
## 选项
### A
```mysql
select sqrt(vx+vy) from (select x^2 as vx, y^2 as vy from points) as t;
```
### B
```mysql
select sqrt(vx + vy) from points where x^2 as vx, y^2 as vy ;
```
### C
```mysql
select id + sqrt(x^2 + y^2) from points;
```
### D
```mysql
select id || sqrt(x^2 + y^2) from points;
```
\ No newline at end of file
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
)
\ No newline at end of file
create table orders (
id int primary key auto_increment,
item_id int,
amount int,
unit_price decimal(12, 4),
total_price decimal(12, 4),
description varchar(2000),
ts timestamp default now(),
deal bool default false
);
\ No newline at end of file
create table points(
id int primary key auto_increment,
x float,
y float
)
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册