首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > Mysql >

mysql上distinct多字段查询

2012-09-29 
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下会报错滴

热点排行