create procedure pName(in a,out b,inout c)
begin
declare row_cus_id int;declare row_track_Id int;
-- 遍歷數據結束標誌
DECLARE done INT DEFAULT FALSE;
declare groupCursor cursor for SELECT id,cus_id from t_ct_cus_track where id in (SELECT MAX(id) FROM t_ct_cus_track GROUP BY cus_id);
-- 將結束標誌綁定到遊標
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;
open groupCursor;
-- 開始循環
read_loop: LOOP
-- 提取遊標裏的數據,這裏只有一個,多個的話也一樣;
FETCH groupCursor INTO row_track_Id,row_cus_id;
-- 聲明結束的時候
IF done THEN
LEAVE read_loop;
END IF;
update t_ct_customer set track_id = row_track_Id where id = row_cus_id;
END LOOP;
end