
清洗数据的时候,发现有重复数据。
之前多用EXCEL处理数据,一键就可以delete了。这次因为数据量相对较大换了mysql。
按照百度搜到的一个高票代码,运行了半天都不对。
一直报错:

即按照mysql语言逻辑不能先select出同一表中的某些值,再update这个表(在同一语句中),即不能依据某字段值做判断再来更新某字段的值。期待Mysql升级,更新这个bug暂时是不可能了,我们还是换个语言逻辑。
整一个中间表过渡:(代码如下)
delete from toutiao where title in (SELECT a.title from
(select title from toutiao group by title
having count(title) > 1) a
)and id not in (SELECT b.id from (select id from toutiao group by title having count(title) > 1) b
)
运行。
完美删除重复项。
果然学和用是两回事,学是规范式按部就班的学,用是灵活变通的用。
如果哪位大神有更好的解决方法,欢迎一起交流。