直接看例子
例子:
table
id name
1 a
2 b
3 c
4 c
5 b
1 通过 distinct 来实现
select distinct name from table
结果:
name
a
b
c
2 通过 group_concat 配合 group by 来实现 (注意:需要mysql 4.1及以上)
select id,group_concat(distinct name) from table group by name
结果:
id name
1 a
2 b
3 c
3 通过
select id, count(distinct name) from table group by name
结果:
id name count(distinct name)
1 a 1
2 b 1
3 b 1
整理自:http://www.cnblogs.com/daiye/archive/2009/11/10/1599977.html