He estado programando por un tema de SEO para mi página del tiempo, un procedimiento que usa cursores, variables, bucles y hace updates, me parece una interesante opción así que aquí os la dejo
delimiter // CREATE PROCEDURE setTop () BEGIN DECLARE done INT DEFAULT 0; DECLARE subdomain_var CHAR(3); DECLARE cur_countries CURSOR FOR select subdomain from country; DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET done = 1; OPEN cur_countries; REPEAT FETCH cur_countries INTO subdomain_var; # Actualizamos los top update item_map inner join (select item_map.id_item_map,item_map.relevant,country.id_country,country.subdomain ,item_map.slug_name,count(*) as total from referer_keyword inner join country on country.subdomain = referer_keyword.subdomain inner join item_map on item_map.fk_id_country = country.id_country and item_map.slug_name = referer_keyword.slug_name where referer_keyword.subdomain = subdomain_var group by 1,2,3,4,5 order by total desc limit 30) as top on item_map.id_item_map = top.id_item_map set item_map.relevant = 20; # Actualizamos el segundo grupo top update item_map inner join (select item_map.id_item_map,item_map.relevant,country.id_country,country.subdomain ,item_map.slug_name,count(*) as total from referer_keyword inner join country on country.subdomain = referer_keyword.subdomain inner join item_map on item_map.fk_id_country = country.id_country and item_map.slug_name = referer_keyword.slug_name where referer_keyword.subdomain = subdomain_var group by 1,2,3,4,5 order by total desc limit 30,90) as top on item_map.id_item_map = top.id_item_map set item_map.relevant = 10; UNTIL done END REPEAT; CLOSE cur_countries; SELECT 'adios'; END //A ver si os sirve de algo, en mysql no nos tenemos que olvidar que existen los procedimiento y funciones, son muy potentes. No olvideis que luego se llamaría tal que "call setTop();" este procedimiento no tiene parametros, pero se los podrías añadir
Comentarios
Publicar un comentario