如何从 Rake 任务向数据库服务器发送这样的查询而不删除“每个”循环中的逐条记录?
delete from data
where uuid in (
select uuid
from data
group by uuid, raw, recdate
having count(*)>1
);
如何从 Rake 任务向数据库服务器发送这样的查询而不删除“每个”循环中的逐条记录?
delete from data
where uuid in (
select uuid
from data
group by uuid, raw, recdate
having count(*)>1
);
ActiveRecord 有delete_all
适合你的方法。请注意,它不会调用销毁回调。http://api.rubyonrails.org/classes/ActiveRecord/Relation.html#method-i-delete_all