
SQL删除重复数据,保留最近修改的一条记录。
使用update更新数据,可能是表设计问题,有重复项。想要根据type和xtype两列删除重复数据,保留最近一条记录。...
使用update更新数据,可能是表设计问题,有重复项。想要根据type和xtype两列删除重复数据,保留最近一条记录。
展开
2个回答
2015-07-03
展开全部
//取到最近一条记录
select type,xtype from 表名 where type='P' and xtype='3' order by execTime desc limit 1;
//拿到type和xtype两个值 type1 和 xtype1
delete from 表名 where type='P' and xtype='3' and type<>type1 and xtype<>xtype1;
这样就可以了。
如果你的表里面有id属性可以用一条sql语句解决:
delete from 表名 where type='P' and xtype='3' and id not in(select id from 表名 where type='P' and xtype='3' order by execTime desc limit 1)
select type,xtype from 表名 where type='P' and xtype='3' order by execTime desc limit 1;
//拿到type和xtype两个值 type1 和 xtype1
delete from 表名 where type='P' and xtype='3' and type<>type1 and xtype<>xtype1;
这样就可以了。
如果你的表里面有id属性可以用一条sql语句解决:
delete from 表名 where type='P' and xtype='3' and id not in(select id from 表名 where type='P' and xtype='3' order by execTime desc limit 1)
已赞过
已踩过<
评论
收起
你对这个回答的评价是?

2025-03-10 广告
IPV6批量查询筛选工具是北京智动益企网络科技有限公司提供的一款高效工具。它支持批量查询IP归属地及服务商,用户可以根据服务商及归属地对IP进行筛选。该工具操作简便,只需将包含IP的文本复制到查询框内,点击开始查询即可。查询完成后,用户可以...
点击进入详情页
本回答由北京智动益企提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询