Non riesco a far funzionare tutta la stored
La query è corretta ma non me la esegue
Codice PHP:
/* stored procedure */
Delimiter $
BEGIN
TRUNCATE TABLE ranks ;
TRUNCATE TABLE defrank ;
DECLARE max_rank INT;
SELECT max(max_links)-1 INTO max_rank FROM
(
SELECT Count(host) AS max_links
FROM rels
GROUP BY linkedhost
) AS tb2;
INSERT INTO ranks (host,links,rank)
SELECT host, links, (10 * (links-1) ) / max_rank
FROM
(
SELECT linkedhost AS host,count(host) AS links
FROM rels
GROUP BY linkedhost
ORDER BY links desc
)AS tb1 ;
INSERT INTO defrank (host,links,points)
SELECT rels.linkedhost as thost,
(
SELECT links
FROM ranks
WHERE host = thost
limit 1
) AS links,
sum(
( SELECT rankpoints.points
FROM ranks INNER JOIN rankpoints on rankpoints.rank = ranks.rank
WHERE ranks.host = rels.host limit 1) )
+
( SELECT rankpoints.points
FROM ranks INNER JOIN rankpoints on rankpoints.rank = ranks.rank
WHERE ranks.host = thost limit 1) AS pr
FROM rels
GROUP BY rels.linkedhost
ORDER BY pr desc;
END$
Delimiter ;
Praticamente l'errore l'ho qui :
TRUNCATE TABLE ranks ;
TRUNCATE TABLE defrank ;
Non mi svuota le 2 tabelle
Se faccio così tutto bene:
TRUNCATE TABLE ranks ;
TRUNCATE TABLE defrank ;
CALL calc_rank() ;
Non è possibile far svuotare le tabelle in automatico ?
Lo so che è poco sbattimento ma volevo capire se sbagliavo io