2018-10-18
閱讀量:
1136
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
注:這樣就能去掉重復(fù)name的字段,且只會匹配出第一個出現(xiàn)的結(jié)果






評論(0)


暫無數(shù)據(jù)
推薦帖子
0條評論
0條評論
0條評論
1條評論