日期:2014-05-16 浏览次数:20878 次
use ss_l; drop FUNCTION if exists `fun_get_diff`; CREATE FUNCTION `fun_get_diff`(rid INT ,time datetime) RETURNS int(11) READS SQL DATA BEGIN DECLARE cost_tot INT ; DECLARE exch_tot INT ; DECLARE diff INT; SELECT IFNULL(SUM(cost_money),0) INTO cost_tot FROM role_money_cost WHERE role_id = rid AND cost_time BETWEEN '0000-00-00 00:00:00' AND time ; SELECT IFNULL(SUM(game_money),0)S INTO exch_tot FROM role_money_exch WHERE role_id = rid AND exch_time BETWEEN '0000-00-00 00:00:00' AND time ; SET diff = exch_tot - cost_tot ; RETURN diff ; END;
delimiter // use ss_l; drop FUNCTION if exists `fun_get_diff`; CREATE FUNCTION `fun_get_diff`(rid INT ,time datetime) RETURNS int(11) READS SQL DATA BEGIN DECLARE cost_tot INT ; DECLARE exch_tot INT ; DECLARE diff INT; SELECT IFNULL(SUM(cost_money),0) INTO cost_tot FROM role_money_cost WHERE role_id = rid AND cost_time BETWEEN '0000-00-00 00:00:00' AND time ; SELECT IFNULL(SUM(game_money),0)S INTO exch_tot FROM role_money_exch WHERE role_id = rid AND exch_time BETWEEN '0000-00-00 00:00:00' AND time ; SET diff = exch_tot - cost_tot ; RETURN diff ; END; delimiter ;
------解决方案--------------------
use ss_l;
drop FUNCTION if exists `fun_get_diff`;
delimiter $$
CREATE FUNCTION `fun_get_diff`(rid INT ,time datetime) RETURNS int(11)
READS SQL DATA
BEGIN
DECLARE cost_tot INT ;
DECLARE exch_tot INT ;
DECLARE diff INT;
SELECT IFNULL(SUM(cost_money),0) INTO cost_tot FROM role_money_cost
WHERE role_id = rid AND cost_time BETWEEN '0000-00-00 00:00:00' AND time ;
SELECT IFNULL(SUM(game_money),0)S INTO exch_tot FROM role_money_exch
WHERE role_id = rid AND exch_time BETWEEN '0000-00-00 00:00:00' AND time ;
SET diff = exch_tot - cost_tot ;
RETURN diff ;
END$$
delimiter ;
------解决方案--------------------
use ss_l;
drop FUNCTION if exists `fun_get_diff`;
delimiter //