Mysql獲取去重后的總數


如果一張表中某個字段存在重復的值,現在我想去重后獲取這個字段值的總數

先看這張表

這張表中的openid有重復值

 

怎么通過sql語句獲取openid的去重總數呢

select count(distinct(openid)) as count from upay_order

 

-------------------------------------------------------------------------------------

補充

1.既可以使用distinct name,也可以用distinct(name)

2.select distinct name from A 對name去重

3.select distinct name, id from A 根據"name+id"來去重

4.select id, distinct name from A;   --會提示錯誤,因為distinct必須放在開頭

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM