wdjh.net
当前位置:首页 >> mysql 取出重复数据 >>

mysql 取出重复数据

重复记录是说所有字段都重复吗,没有主键是吗,如果是这样,删除最后一条还是第一条没有区别; 如果说重复记录是不包括主键id的字段,可以使用order by id来排序,获取到最后一条数据 或者用group by(重复的字段),然后用max(id)获取最后的一条

SELECT *, Row_Number() OVER (partition by title ORDER BY month desc) FROM 表

delete from mygame_article where id not in ( select max(id) from mygame_article group by title);

select userid,username,userlevel from tb where userid not in(select userid from tb group by username,userlevel having count(1)=1)先找出没有重复的userid,然后过滤这些userid,其余的就是有重复的了

sql:select distinct 列名 from 表名,使用distinct 关键字去除重复值

select name, sum(count) as total from table group by name

select distinct * from table 条件。

假设表名为test: select * from (select *, concat(name,code) as __f from test order by date desc) __t group by __f;

查看可用如下方法: 1、创建测试表,插入数据: create table product(id int,name varchar(10),totol int)insert into product values (1,'香蕉',100)insert into product values (2,'橘子',67)insert into product values (3,'葡萄',89)insert...

select distinct question_type from question

网站首页 | 网站地图
All rights reserved Powered by www.wdjh.net
copyright ©right 2010-2021。
内容来自网络,如有侵犯请联系客服。zhit325@qq.com