having.md 990 字节
Newer Older
M
having  
Mars Liu 已提交
1 2 3 4
# Having

 Joe 要从 employee 表
 
fix bug  
张志晨 已提交
5
```sql
M
having  
Mars Liu 已提交
6 7 8 9 10 11 12 13 14 15 16
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
having  
Mars Liu 已提交
24 25
## 答案

fix bug  
张志晨 已提交
26
```sql
27 28 29 30
select dept 
from employee 
group by dept 
having sum(salary) > 100000;
M
having  
Mars Liu 已提交
31 32 33 34 35 36
```

## 选项

### A

fix bug  
张志晨 已提交
37
```sql
38 39 40
select dept 
from employee 
group by dept where sum(salary) > 100000;
M
having  
Mars Liu 已提交
41 42 43 44
```

### B

fix bug  
张志晨 已提交
45
```sql
46 47 48 49
select dept 
from employee 
where sum(salary) > 100000 
group by dept;
M
having  
Mars Liu 已提交
50 51 52 53
```

### C

fix bug  
张志晨 已提交
54
```sql
55 56 57 58
select dept 
from employee 
where sum(salary) > 100000 
order by dept;
M
having  
Mars Liu 已提交
59 60 61 62
```

### D

fix bug  
张志晨 已提交
63
```sql
64 65 66 67
select dept 
from employee 
group by dept 
where sum(salary) > 100000;
M
having  
Mars Liu 已提交
68 69 70
```