ok
DROP PROCEDURE
IF EXISTS truncate_insert_rank_month;
DELIMITER /w/ CREATE PROCEDURE truncate_insert_rank_month ()
BEGIN SET @w = 10 ; TRUNCATE rank_month ;
WHILE @w < 110 DO
INSERT INTO rank_month (
fk_country,
fk_categoryid,
topx,
history_year,
history_month,
coin_sum,
amount_sum
) SELECT
country,
categoryid,
@w,
DATE_FORMAT(grab_date, '%Y'),
DATE_FORMAT(grab_date, '%M'),
SUM(grab_coin),
SUM(grab_amount)
FROM
grab_rank
WHERE
grab_amount_rank < (@w + 1)
GROUP BY
country,
categoryid,
DATE_FORMAT(grab_date, '%Y'),
DATE_FORMAT(grab_date, '%M') ;
SET @w = @w + 10 ;
END
WHILE ;
END/w/
DELIMITER;
CALL truncate_insert_rank_month;
ok
DROP PROCEDURE
IF EXISTS truncate_insert_rank_month;
DELIMITER /w/ CREATE PROCEDURE truncate_insert_rank_month ()
BEGIN
TRUNCATE rank_month ;
SET @w = 10 ;
WHILE @w < 110 DO
INSERT INTO rank_month (
fk_country,
fk_categoryid,
topx,
history_year,
history_month,
coin_sum,
amount_sum
) SELECT
country,
categoryid,
@w,
DATE_FORMAT(grab_date, '%Y'),
DATE_FORMAT(grab_date, '%M'),
SUM(grab_coin),
SUM(grab_amount)
FROM
grab_rank
WHERE
grab_amount_rank < (@w + 1)
GROUP BY
country,
categoryid,
DATE_FORMAT(grab_date, '%Y'),
DATE_FORMAT(grab_date, '%M') ;
SET @w = @w + 10 ;
END
WHILE ;
END/w/
DELIMITER;
CALL truncate_insert_rank_month;
DROP PROCEDURE
IF EXISTS truncate_insert_rank_month;
DELIMITER /w/ CREATE PROCEDURE truncate_insert_rank_month ()
BEGIN
TRUNCATE rank_month ;
DECLARE w INT ;
SET w = 10 ;
WHILE w < 110 DO
INSERT INTO rank_month (
fk_country,
fk_categoryid,
topx,
history_year,
history_month,
coin_sum,
amount_sum
) SELECT
country,
categoryid,
w,
DATE_FORMAT(grab_date, '%Y'),
DATE_FORMAT(grab_date, '%M'),
SUM(grab_coin),
SUM(grab_amount)
FROM
grab_rank
WHERE
grab_amount_rank < (w + 1)
GROUP BY
country,
categoryid,
DATE_FORMAT(grab_date, '%Y'),
DATE_FORMAT(grab_date, '%M') ;
SET w = w + 10 ;
END
WHILE ;
END/w/
DELIMITER;
CALL truncate_insert_rank_month;
[Err] 1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'DECLARE w INT ;
SET w = 10 ;
WHILE w < 110 DO
INSERT INTO rank_month (
fk' at line 4
http://dev.mysql.com/doc/refman/5.7/en/stored-programs-defining.html
DROP PROCEDURE
IF EXISTS truncate_insert_rank_month;
DELIMITER /w/ CREATE PROCEDURE truncate_insert_rank_month ()
BEGIN DECLARE w INT ; TRUNCATE rank_month ;
SET w = 10 ;
WHILE w < 110 DO
INSERT INTO rank_month (
fk_country,
fk_categoryid,
topx,
history_year,
history_month,
coin_sum,
amount_sum
) SELECT
country,
categoryid,
w,
DATE_FORMAT(grab_date, '%Y'),
DATE_FORMAT(grab_date, '%M'),
SUM(grab_coin),
SUM(grab_amount)
FROM
grab_rank
WHERE
grab_amount_rank < (w + 1)
GROUP BY
country,
categoryid,
DATE_FORMAT(grab_date, '%Y'),
DATE_FORMAT(grab_date, '%M') ;
SET w = w + 10 ;
END
WHILE ;
END/w/
DELIMITER;
CALL truncate_insert_rank_month; DROP PROCEDURE
IF EXISTS truncate_insert_rank_week;
DELIMITER /w/ CREATE PROCEDURE truncate_insert_rank_week ()
BEGIN DECLARE w INT ; TRUNCATE rank_week ;
SET w = 10 ;
WHILE w < 110 DO
INSERT INTO rank_week (
fk_country,
fk_categoryid,
topx,
history_year,
history_week,
coin_sum,
amount_sum
) SELECT
country,
categoryid,
w,
DATE_FORMAT(grab_date, '%Y'),
DATE_FORMAT(grab_date, '%V'),
SUM(grab_coin),
SUM(grab_amount)
FROM
grab_rank
WHERE
grab_amount_rank < (w + 1)
GROUP BY
country,
categoryid,
DATE_FORMAT(grab_date, '%Y'),
DATE_FORMAT(grab_date, '%V') ;
SET w = w + 10 ;
END
WHILE ;
END/w/
DELIMITER;
CALL truncate_insert_rank_week; DROP PROCEDURE
IF EXISTS truncate_insert_rank_all;
DELIMITER /w/ CREATE PROCEDURE truncate_insert_rank_all ()
BEGIN DECLARE w INT ; TRUNCATE rank_all ;
SET w = 10 ;
WHILE w < 110 DO
INSERT INTO rank_all (
fk_country,
fk_categoryid,
topx,
coin_sum,
amount_sum
) SELECT
country,
categoryid,
w,
SUM(grab_coin),
SUM(grab_amount)
FROM
grab_rank
WHERE
grab_amount_rank < (w + 1)
GROUP BY
country,
categoryid ;
SET w = w + 10 ;
END
WHILE ;
END/w/
DELIMITER ; CALL truncate_insert_rank_all;