Database field: id, user_id, date ,... other fields: MySQLBEGIN # Routinebodygoeshere... * If you query more than 1000 entries, delete the statement * DECLAREact_friends_user_idINT; DECLAREact_friends_min_idINT; DECLAREdnINTdefault0; * define the query statement * DECLAREactCURSOR
Database field: id, user_id, date ,... other fields: MySQL BEGIN # Routine body goes here... /* delete a query that contains more than 1000 entries */DECLARE act_friends_user_id INT; DECLARE act_friends_min_id INT; DECLARE dn INT default 0;/* define the query statement */DECLARE act CURSOR
Database field: id, user_id, date,... other fields MySQL
BEGIN # Routine body goes here... /* If you query more than 1000 entries, delete the statement */DECLARE act_friends_user_id INT; DECLARE act_friends_min_id INT; DECLARE dn INT default 0; /* define the query statement */DECLARE act cursor for select user_id FROM act_friends group by user_id having count (user_id)> 1000; declare exit handler for not found set dn = 1; /* Start the loop */OPEN act; act_loop: LOOPFETCH act INTO act_friends_user_id;/* jump out of the cursor loop when the condition is not found at the end of the loop */if dn = 1 THENLEAVE act_loop; END if;/* obtain the minimum ID value of the latest 1000 data records */select min (id) into act_friends_min_id from (select id from act_friends where user_id = act_friends_user_id order by date DESC limit 1000) as temp; SELECT act_friends_min_id; delete from act_friends where user_id = act_friends_user_id AND id <act_friends_min_id; end loop; CLOSE act; END