SQL創建:
create PROCEDURE daily_max_avg_online() BEGIN declare max_online int; declare avg_online int; declare time TIMESTAMP; declare cur cursor for select MAX(online_num),round(avg(online_num)), DATE_FORMAT(statistical_time ,'%y-%m-%d') from real_time_online_statistics group by DATE_FORMAT(statistical_time ,'%y-%m-%d'); open cur; cur:loop FETCH cur into max_online,avg_online,time; insert into daily_max_avg_online_statistics(id,max_online_num,avg_online_num,statistical_time) values(UUID(),max_online,avg_online,time); end loop cur; close cur; END;
Navicat創建:
1,.點擊數據庫中的函數 --> 新建函數
2.一路點擊完成,進入創建存儲過程的界面
3.保存(Ctrl+S) -- > 輸入存儲過程名稱 --> 完成存儲過程的創建