0

rake task で次のクエリを実行するにはどうすればよいですか?

DELETE FROM crawled_categories WHERE id NOT IN (
   SELECT id FROM (
       SELECT DISTINCT(site_id, parent_category, breadcrumb), max(id) AS id
       FROM crawled_categories 
       WHERE map_id is null
       GROUP BY site_id, parent_category, breadcrumb
   ) AS tmp
) AND map_id IS NULL
4

1 に答える 1

0

私は次のコードを試しましたが、うまくいきました:

ActiveRecord::Base.connection.execute("DELETE FROM crawled_categories WHERE id NOT IN ( SELECT id FROM ( SELECT DISTINCT(site_id, parent_category, breadcrumb), max(id) AS id FROM crawled_categories WHERE map_id is null GROUP BY site_id, parent_category, breadcrumb ) AS tmp ) AND map_id IS NULL")
于 2012-08-20T13:15:13.367 に答える