BEGIN
#Routine body goes here... I just do it ,even it's make me feel sick;
DECLARE daycount DOUBLE DEFAULT 0;
DECLARE monthcount DOUBLE DEFAULT 0 ;
DECLARE yearcount DOUBLE DEFAULT 0;
IF(last_interest_date is not null)THEN
IF(dates is not null)THEN
set daycount= (select SUM(account_balance*interest_rate/100/365) from account_balance_snap where dell_status = 0 and user_id =user_id and card_id = rowid);
update account_balance_snap SET dell_status = 1 where user_id =user_id and card_id = rowid;
set monthcount= (select sum(month_interest) from account_balance_month where dell_status = 0 and user_id =user_id and card_id = rowid);
update account_balance_month SET dell_status = 1 where user_id =user_id and card_id = rowid;
set yearcount= (select sum(year_interest) from account_balance_year where dell_status = 0 and user_id =user_id and card_id = rowid);
update account_balance_year SET dell_status = 1 where user_id =user_id and card_id = rowid;
set countInterest =daycount+monthcount+yearcount;
SELECT countInterest;
ELSE
END IF;
END
這樣求出來的 countInterest 一直是空, 如果set daycount = 中加 @, 則會回傳0; 求解!
uj5u.com熱心網友回復:
自己結吧!
因為如果查詢出資料為空進行+ 計算會使結果最終為NULL!
解決辦法就是通過判斷NULL,賦值為0,進行準確計算!
uj5u.com熱心網友回復:
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/93787.html
標籤:MySQL
下一篇:sql回圈計算問題
