min.md 873 字节
Newer Older
M
Mars Liu 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
# 最小值练习

Joe 想要得到 employee 表

```mysql
create table employee
(
    id     serial primary key,
    name   varchar(256),
    dept   varchar(256),
    salary decimal(12, 4)
);
```

中每个部门工资最低的员工的工资信息,这条查询应该怎么写?

M
Mars Liu 已提交
17 18
<hr/>

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

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

M
Mars Liu 已提交
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
## 答案

```mysql
select dept, min(salary) from employee group by dept;
```

## 选项

### A

```mysql
select dept, min(salary) from employee;
```

### B

```mysql
select dept, min(salary) from employee;
```

### C

```mysql
select dept, min(salary) from employee;
```

### D

```mysql
M
Mars Liu 已提交
53
select dept, min(total) from employee;
M
Mars Liu 已提交
54
```