惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

腾讯CDC
Microsoft Azure Blog
Microsoft Azure Blog
L
LangChain Blog
Y
Y Combinator Blog
Microsoft Security Blog
Microsoft Security Blog
宝玉的分享
宝玉的分享
B
Blog RSS Feed
MongoDB | Blog
MongoDB | Blog
Jina AI
Jina AI
D
Docker
B
Blog
Engineering at Meta
Engineering at Meta
Last Week in AI
Last Week in AI
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
I
InfoQ
G
Google Developers Blog
博客园 - Franky
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
The GitHub Blog
The GitHub Blog
T
The Blog of Author Tim Ferriss
大猫的无限游戏
大猫的无限游戏
阮一峰的网络日志
阮一峰的网络日志
U
Unit 42

博客园 - M'

AndroidStudio修改项目名称 cocos2dx2.x&3.x部分函数对照表 Ubuntu 安装mono 关于BigDecimal.ROUND_HALF_UP与ROUND_HALF_DOWN android 常用框架 理解assign,copy,retain变strong SQLSERVER2008R2正确使用索引 除非 Windows Activation Service (WAS)和万维网发布服务(W3SVC)均处于运行状态,否则无法启动网站。目前,这两项服务均处于停止状态。 Android资源命名规范 eclipse导入Android项目后,项目的名称变为了主Activity的名称 C语言位运算详解[转] Android Message里传送的数据[转] Android---组件篇---Handler的使用(1)[转] 自定义登录后台(authentication backend)[转] Nginx配置文件详细说明[转] python 进制转换[转] MySQL一些优化[转] C# Stream 和 byte[] 之间的转换[转] DotLucene(Lucene.Net)研究[转]
MySQL 去除重复的方法
M' · 2013-01-02 · via 博客园 - M'

直接看例子

例子:

     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