2019-01-17
閱讀量:
802
MySQL去重查詢distinct
table表如下:
id name
1 a
2 b
3 c
4 c
5 b
1、select distinct name from table
----------
name
a
b
c
2、select distinct name, id from table
----------
id name
1 a
2 b
3 c
4 c
5 b
distinct同時(shí)作用了兩個(gè)字段
3、select id, distinct name from table
----------
出錯(cuò)
注:distinct必須放在所有字段之前
4、select *, count(distinct name) from table group by name
----------
id name count(distinct name)
1 a 1
2 b 1
3 c 1
注:這樣就能去掉重復(fù)name的字段,且只會(huì)匹配出第一個(gè)出現(xiàn)的結(jié)果






評(píng)論(0)


暫無(wú)數(shù)據(jù)
CDA考試動(dòng)態(tài)
CDA報(bào)考指南
推薦帖子
0條評(píng)論
0條評(píng)論
0條評(píng)論
1條評(píng)論