Distinct的作用是用於從指定集合中消除重復的元組,經常和count搭檔工作,語法如下
COUNT( { [ ALL | DISTINCT ] expression ] | * } )
這時,可能會碰到如下情況,你想統計同時有多列字段重復的數目,你可能會立馬想到如下方法:
selectcount( distinct col1 , col2 , col3 , .......) from table
但是,這樣是不允許的,因為count是不能統計多個字段的,雖然distinct是可行的。
有種比較直接的方法就是把消除重復后在統計查詢:
select count(*) from (select distinct col1 ,col2 , col3 from table)A