先验证
select u.md5,u.id as uid,a.id as aid,u.dlcount
from zb_url u
left join zb_article partition(p0, p2017) a on u.md5=a.url_md5
where u.dlcount > 0 and a.id is null
再执行
update zb_url a
left join zb_article partition(p0, p2017) b
on a.md5=b.url_md5
set a.dlcount=0
where a.dlcount>0 and b.id is null
参考资料
https://stackoverflow.com/a/806925/2007704
本文介绍了一种使用SQL语句来验证并清理数据库中冗余记录的方法。首先通过联表查询找出已被引用但不再存在的文章链接,然后更新这些链接的下载计数为0。这种方法有助于维护数据库的整洁性和准确性。
483

被折叠的 条评论
为什么被折叠?



