现有一个视频系统,每秒记录一条用户的观看情况,后来用户多了发现实在太影响行性能了,打算每分钟记录一次。
思路:循环将计算每个用户的观看日志,并整除60,得到的数值即为要保留的日志数量。
drop procedure if exists tomin;
delimiter $$
create procedure tomin()
begin
declare s int default 0;
declare stuId int;
declare logCount int;
DECLARE students CURSOR FOR select id from wk_student_info where loginName is not NULL;
DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET s=1;
OPEN students;
fetch students into stuId;
while s <> 1 do
select (1 + count(*) - count(*) div 60) into logCount from wk_study_info where studentId = stuId;
select stuId,logCount;
delete from wk_study_info where studentId = stuId limit logCount;
fetch students into stuId;
end while;
close students;
end $$
delimiter ;
call tomin();
最后发现,还是你的博客文章页舒服。。。。 [><]
你不是说丑么hhh