mysql下distinct多字段查询数据库结构:? table?? id name?? 1 a?? 2 b?? 3 c?? 4 c?? 5 b? 需求:查询name
mysql下distinct多字段查询
数据库结构:? table
?? id name
?? 1 a
?? 2 b
?? 3 c
?? 4 c
?? 5 b?
需求:查询name不重复的数据(含ID)
?
select *, count(distinct name) from table group by name
结果:
?? id name count(distinct name)
?? 1 a 1
?? 2 b 1
?? 3 c 1
?
注:此法只在mysql下适用,在oracle、mssql下会报错滴
