mysql数据库 删除重复项 保留ts最新的项
2016-07-06 15:29
274 查看
sql语句是:
delete from table
where key in (select a.
key key from (select * from
table) a where niandu='2016' group by a. key having count(a.key) > 1)
and ts not in (select max(b.ts) from (select * from
table) b group by b.key having count(b.key )>1)
其中
(select * from table) a 是为了在将table当成是子集,防止you cant specify target table for update in from clause 错误。
delete from table
where key in (select a.
key key from (select * from
table) a where niandu='2016' group by a. key having count(a.key) > 1)
and ts not in (select max(b.ts) from (select * from
table) b group by b.key having count(b.key )>1)
其中
(select * from table) a 是为了在将table当成是子集,防止you cant specify target table for update in from clause 错误。
相关文章推荐
- C# 小数位数保留的方法集锦
- PHP实现过滤掉非汉字字符只保留中文字符
- C#中Decimal类型截取保留N位小数并且不进行四舍五入操作
- JavaScript保留关键字汇总
- 理解VMware资源池
- sql的四舍六入五成双的函数 (1)
- java之保留几位小数的几种方式及添加千位分隔符
- JavaScript四舍五入并保留两位小数
- 关于Android apk签名问题
- php中form表单提交保留空格和回车
- DHCP服务的配置与管理(4) DHCP服务器的配置
- 保留符合要求的N个条目,括号匹配
- 保留两位小数位
- django的form组件的插件相关参数和保留内容
- Java:对double值进行四舍五入,保留两位小数的几种方法
- python 保留2位小数
- MVC dropdownist绑定list之后除去list中的重复项
- java 保留小数后N位小数
- iOS清除角标,通知栏“通知”保留
- Java:对double值进行四舍五入,保留两位小数的几种方法