having.md 730 字节
Newer Older
M
having  
Mars Liu 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 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
# Having

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

中得到每月工资开支超过十万的部门,这个查询应该怎么写?

## 答案

```mysql
select dept from employee group by dept having sum(salary) > 100000;
```

## 选项

### A

```mysql
select dept from employee group by dept where sum(salary) > 100000;
```

### B

```mysql
select dept from employee where sum(salary) > 100000 group by dept;
```

### C

```mysql
select dept from employee where sum(salary) > 100000 order by dept;
```

### D

```mysql
select dept from employee group by dept where sum(salary) > 100000;
```