mysql count distinct 去重
程序员文章站
2024-02-11 11:45:22
...
在 select 语句中,去重通常是使用distinct关键字及聚合函数group by,如:
SELECT DISTINCT name FROM students
SELECT id,name FROM students
GROUP BY id
HAVING id>100
在count语句中,需要这样写:
SELECT count(DISTINCT name) FROM students
对全表统计进行去重的话,不可使用count(1)及count(*)
如: ,需要指定字段SELECT count(DISTINCT 1) FROM students