distinct.md 793 字节
Newer Older
M
having  
Mars Liu 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
# Distinct

Joe 想统计以下 goods 表

```mysql
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
)
```

中的商品有多少种不同的价格,他应该如何写这条查询?

M
Mars Liu 已提交
19 20
点击进入[MySQL实战练习环境](https://mydev.csdn.net/product/pod/new?image=cimg-centos7-skilltreemysql&connect=auto&create=auto&utm_source=skill)

M
having  
Mars Liu 已提交
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 50 51
## 答案

```mysql
select count(distinct price) from goods;
```

## 选项

### A

```mysql
select count(distinct *) from goods;
```

### B

```mysql
select distinct count(price) from goods;
```

### C

```mysql
select count(price) from goods;
```

### D

```mysql
select distinct price from goods;
```