我有以下代碼MySQL事件每年的運行計算
CREATE EVENT myevent2
ON SCHEDULE EVERY '1' YEAR
STARTS commit_date + INTERVAL 1 YEAR
DO
UPDATE lms.loan
if new.app_loan_type='Computer Loan' then
SET NEW.app_yearly_intrst = (NEW.app_ln_amnt *(NEW.computer_interest/100));
end if;
if new.app_loan_type="Miscellaneous Loan" then
SET NEW.app_yearly_intrst = (NEW.app_ln_amnt *(NEW.miscellaneous_interest/100));
end if;
if new.app_loan_type="Motor Vehicle Loan" then
SET NEW.app_yearly_intrst = (NEW.app_ln_amnt *(NEW.motor_vehicle_interest/100));
end if;
if new.app_loan_type="Motor Vehicle Insurance Loan" then
SET NEW.app_yearly_intrst = (NEW.app_ln_amnt *(NEW.mv_insurance_interest/100));
end if;
if new.app_loan_type="Motor Vehicle Repair Loan" then
SET NEW.app_yearly_intrst = (NEW.app_ln_amnt *(NEW.mv_repair_interest/100));
end if;
if new.app_loan_type="Salary Advance Loan" then
SET NEW.app_yearly_intrst = (NEW.app_ln_amnt *(NEW.salary_advance_interest/100));
end if;
if new.app_loan_type="Tertiary Loan" then
SET NEW.app_yearly_intrst = (NEW.app_ln_amnt *(NEW.tertiary_interest/100));
end if;
SET NEW.app_mnthly_intrest = (NEW.app_yearly_intrst/12);
SET NEW.app_quarterly_intrest = (NEW.app_mnthly_intrest * 3);
SET NEW.app_amnt_owed = (NEW.app_ln_amnt+ NEW.app_yearly_intrst);
END$$
我想創建一個事件來計算兩種類型的貸款利息:「計算機貸款」和「雜項貸款」 ..等,在每年的基礎上,然而每年的基礎依賴於commit_date列,這將是來自commit_date列的一年,那麼如果app_loan_type是'電腦貸款'或'雜項貸款',那麼計算每年的利息也計算每月的利息,季度利息和欠款總額,但我的主要問題是如何將commit_date和當前日期的間隔設置爲1年
所以你說的答案從@jeffery_the_wind你上面的不管用? – dames 2012-04-10 14:45:22
我不認爲他說了一些與我不同的東西... – Vikram 2012-04-10 15:34:41
我在@jeffery_the_wind的答案中得到以下錯誤,即時試圖找到錯誤,但它給了我一個溫暖的時間,請如果我能再次請求一些幫助# 1064 - 你的SQL語法錯誤;檢查對應於你的MySQL服務器版本正確的語法使用手動附近「如果DATEDIFF(日期(NOW()),commit_date)> = 365那麼如果new.app_loan_type =「」在第7行 – dames 2012-04-10 16:19:36