2014-07-24 61 views
-1
SET @total_people = (SELECT COUNT(*) FROM tbl_members); 
SET @point_available = (SELECT free_bonus from tbl_bonus); 

SET @must_use = @total_people * 15; 

IF @point_available > @must_use THEN 

SET @bonuses = @money_available - @must_use ; 
UPDATE tbl_member SET points = points + 15 WHERE 1; 
ELSE 

SET @bonuses = @points_available/15; 
UPDATE tbl_member SET points = points + 15 LIMIT @bonuses; 

END IF; 

SELECT @bonuses 

:(如果它不工作:(.....整個聲明:「(一下如果在mysql中陳述

有關XD ....新手在這裏...和IM試圖遺憾使它成爲英文的XD ......並且它真的很難解釋哈哈btw ...即時通訊試圖做一個存儲過程即時通訊有一個問題,如果陳述...我想設置一個變量,處理總成員..和我得到的總積分... free_points =總成員數* 15;如果總積分大於自由積分,則更新tbl_member積分=積分+15其他所有其他積分都會獲得免費積分......限制積分/ 15;對不起,英文很差XD

錯誤:

#1064 - 您的SQL語法錯誤;檢查對應於你的MySQL服務器版本正確的語法使用近「IF point_available> must_use手動THEN

+0

什麼不行呢?它是錯誤的,還是不產生你期望的輸出,或者是什麼? –

+0

「*不工作*」不是有效的MySQL錯誤消息。 –

+0

什麼是問題和錯誤,請解釋它 – Farrokh

回答

1

變化這一個:

SET @point_available =(SELECT從tbl_bonus COUNT(free_bonus));

0

-_-

日Thnx大家...我找到了解決辦法...

PREPARE STMT FROM 
"UPDATE tbl_member SET points = points + 15 LIMIT ? "; 

SET @1st = (SELECT COUNT(*) FROM tbl_member); 
SET @2nd = (SELECT free_bonus FROM tbl_bonus); 
SET @3rd = @1st * 15; 
SET @4th = @2nd/15; 
SET @5th = (SELECT IF(@3rd > @2nd,@4th,@1st)); 

EXECUTE STMT USING @5TH; 
+0

實際上我意外地使用其他代碼在這裏發現股票溢出構造它-_- –