view.md 1.2 KB
Newer Older
M
having  
Mars Liu 已提交
1 2 3 4
# 视图

Joe 需要给 goods 表

fix bug  
张志晨 已提交
5
```sql
M
having  
Mars Liu 已提交
6 7 8 9 10 11 12 13 14 15 16 17 18
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 的商品价格和名称,下列选项中正确的是:

M
Mars Liu 已提交
19 20
<hr/>

F
feilong 已提交
21
点击进入[MySQL实战练习环境](https://mydev.csdn.net/product/pod/new?image=cimg-centos7-skilltreemysql&connect=auto&create=auto&utm_source=skill){target="_blank"}。
F
feilong 已提交
22

F
feilong 已提交
23 24
* `show databases;` 列出所有数据库
* `show tables;` 列出所有表
M
Mars Liu 已提交
25

M
having  
Mars Liu 已提交
26 27
## 答案

fix bug  
张志晨 已提交
28
```sql
M
having  
Mars Liu 已提交
29 30 31 32 33 34 35 36 37 38 39
CREATE VIEW view_name_price 
    AS 
    SELECT name, price 
    FROM goods
    WHERE price > 1000;
```

## 选项

### A

fix bug  
张志晨 已提交
40
```sql
M
having  
Mars Liu 已提交
41 42 43 44 45 46 47 48
CREATE VIEW view_name_price 
    AS 
    SELECT name, price 
    FROM goods;
```

### B

fix bug  
张志晨 已提交
49
```sql
M
having  
Mars Liu 已提交
50 51 52 53 54 55 56 57 58
CREATE VIEW view_name_price 
    AS 
    SELECT * 
    FROM goods
    WHERE price > 1000;
```

### C

fix bug  
张志晨 已提交
59
```sql
M
having  
Mars Liu 已提交
60 61 62 63 64 65 66 67 68 69 70
CREATE VIEW view_name_price
    AS 
BEGIN
    SELECT name, price
    FROM goods
    WHERE price > 1000;
END;
```

### D

fix bug  
张志晨 已提交
71
```sql
M
having  
Mars Liu 已提交
72 73 74 75 76 77 78 79
CREATE VIEW view_name_price
    AS 
BEGIN
    SELECT name, price
    FROM goods
    WHERE price > 1000;
END;
```