行が挿入される残高と時間に応じて、5 分ごとにテーブル 'try_event' の残高を更新するイベントを作成しました。
イベントコード:
delimiter $$
CREATE EVENT `event`
ON SCHEDULE every 1 second
DO
begin
-- update balance by 2%
UPDATE try_event
SET Balance = case
WHEN timestampdiff(minute,date_created,current_timestamp) >0 and timestampdiff(minute,date_created,current_timestamp) MOD 5 = 0 and (balance>2000 and balance<3000) then Balance * 1.02
end;
end $$
delimiter ;
テーブル :
create table try_event(balance numeric(10,2) not null,date_created timestamp);
挿入された行:
insert into try_event values(2500,default);
insert into try_event values(1000,default);
しかし、それでもbalance=2500
5分後に与えています。
" " を削除すると(balance>2000 and balance<3000)
、残高列全体が更新され、結果は次のようになります。
2550
1020