mysql怎么取重复记录 mysql查询一列重复数据

MySql怎么查询重复的数据

select name,sum(num) from table group by name

成都创新互联专注于企业营销型网站、网站重做改版、坡头网站定制设计、自适应品牌网站建设、H5建站商城网站建设、集团公司官网建设、成都外贸网站建设、高端网站制作、响应式网页设计等建站业务,价格优惠性价比高,为坡头等各大城市提供网站开发制作服务。

--group by 分组查询可以实现,根据名称分组查询累加数量

mysql 怎样找出重复的记录

SQL语句:SELECT `lcontent` FROM `caiji_ym_liuyan`这样查询的时候就会有很多重复的记录

例子:

就会出现这样的重复

2

修改后的SQL语句:

SELECT distinct(`lcontent`) FROM `caiji_ym_liuyan`

查询结果:

mysql去重复 保留一条

mysql去重复 保留一条怎么操作呢?一起来看下吧:

1、查找表中多余的重复记录,重复记录是根据单个字段(peopleId)来判断

SELECT     * FROM     people WHERE     peopleId IN (         SELECT             peopleId         FROM             people         GROUP BY             peopleId         HAVING             count(peopleId)  1     )

2、删除表中多余的重复记录,重复记录是根据单个字段(peopleId)来判断,只留有rowid最小的记录

DELETE FROM     people WHERE     peopleName IN (         SELECT             peopleName         FROM             people         GROUP BY             peopleName         HAVING             count(peopleName)  1     ) AND peopleId NOT IN (     SELECT         min(peopleId)     FROM         people     GROUP BY         peopleName     HAVING         count(peopleName)  1 )

3、查找表中多余的重复记录(多个字段)

SELECT     * FROM     vitae a WHERE     (a.peopleId, a.seq) IN (         SELECT             peopleId,             seq         FROM             vitae         GROUP BY             peopleId,             seq         HAVING             count(*)  1     )

4、删除表中多余的重复记录(多个字段),只留有rowid最小的记录

DELETE FROM     vitae a WHERE     (a.peopleId, a.seq) IN (         SELECT             peopleId,             seq         FROM             vitae         GROUP BY             peopleId,             seq         HAVING             count(*)  1     ) AND rowid NOT IN (     SELECT         min(rowid)     FROM         vitae     GROUP BY         peopleId,         seq     HAVING         count(*)  1 )

5、查找表中多余的重复记录(多个字段),不包含rowid最小的记录

SELECT     * FROM     vitae a WHERE     (a.peopleId, a.seq) IN (         SELECT             peopleId,             seq         FROM             vitae         GROUP BY             peopleId,             seq         HAVING             count(*)  1     ) AND rowid NOT IN (     SELECT         min(rowid)     FROM         vitae     GROUP BY         peopleId,         seq     HAVING         count(*)  1 )

6、消除一个字段的左边的第一位:

UPDATE tableName SET [ Title ]= RIGHT ([ Title ],(len([ Title ]) - 1)) WHERE     Title LIKE '村%'

7、消除一个字段的右边的第一位:

UPDATE tableName SET [ Title ]= LEFT ([ Title ],(len([ Title ]) - 1)) WHERE     Title LIKE '%村'

8、假删除表中多余的重复记录(多个字段),不包含rowid最小的记录

UPDATE vitae SET ispass =- 1 WHERE     peopleId IN (         SELECT             peopleId         FROM             vitae         GROUP BY             peopleId


分享标题:mysql怎么取重复记录 mysql查询一列重复数据
网页地址:http://ybzwz.com/article/docedps.html