题解 | #删除emp_no重复的记录,只保留最小的id对应的记录。#

删除emp_no重复的记录,只保留最小的id对应的记录。

http://www.nowcoder.com/practice/3d92551a6f6d4f1ebde272d20872cf05

总的来说就是要根据emp_no分组然后找到每组id最小的record。

delete from titles_test
where id not in (select * from (select min(id) from titles_test
                                group by emp_no) as temp)
delete from titles_test
where id in (select temp.id from (select *, rank() over (partition by emp_no order by id) as ranking
                             from titles_test) as temp
                             where temp.ranking > 1) 
全部评论

相关推荐

11-03 17:57
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务