DELIMITER //
create PROCEDURE urank(in today DATE)
begin
declare uid INT;
declare t DATE;
declare c INT;
declare done INT DEFAULT 0;
declare cur_rank cursor for select userid,time from user_action where time between DATE(today) and DATE_ADD(today,INTERVAL 1 DAY);
DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET done = 1;
set c = 0;
OPEN cur_rank;
FETCH NEXT FROM cur_rank INTO uid, t; 
LOOP_LABLE:loop
set t = DATE(t);
select userid,time from user_action where userid = uid and time between DATE(DATE_SUB(t,INTERVAL 1 DAY)) and t;
set c = c+1;
if userid is null then
insert into rankTemp(ranknum,userid) values(c,userid);
set c = 0;
end if;
end loop;
CLOSE cur_rank;
end;
//
一直报错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 'set c = c+1;
if userid is null then
insert into rankTemp(ranknum,userid) value' at line 15