如果一張表中某個字段存在重復的值,現在我想去重后獲取這個字段值的總數
先看這張表
這張表中的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必須放在開頭