291294878

2018-10-18   阅读量: 846

数据分析师 Mysql

SQL中distinct的用法?

扫码加入数据分析学习群

table表如下

id name

1 a

2 b

3 c

4 c

5 b

Test1

select distinct name from table

----------

name

a

b

c

Test2

select distinct name, id from table

----------

id name

1 a

2 b

3 c

4 c

5 b

注:distinct同时作用了两个字段

Test3

select id, distinct name from table

----------

出错

注:distinct必须放在所有字段之前

Test4

select *, count(distinct name) from table group by name

----------

id name count(distinct name)

1 a 1

2 b 1

3 c 1

注:这样就能去掉重复name的字段,且只会匹配出第一个出现的结果

添加CDA认证专家【维克多阿涛】,微信号:【cdashijiazhuang】,提供数据分析指导及CDA考试秘籍。已助千人通过CDA数字化人才认证。欢迎交流,共同成长!
0.0000 0 2 关注作者 收藏

评论(0)


暂无数据

推荐课程