当调用一个连接字符串都不为空的过程时,有时mysql会返回null。重新启动后,sql可以正常工作一段时间。
sql和结果在这里:
select @sql,@sql2,ifnull(@sql,""),ifnull(@sql2,""),concat(@sql,@sql2);
Mysql版本是5.6.19。需要改变my.cnf? 3Q。
以下整个程序:
params:IN v_begin_time
DATEtime,IN v_finish_time
DATEtime,IN v_channel_id
varchar(128),IN v_server_id
varchar(128)
begin
DECLARE sql1 varchar(8000);
set @begin_time = DATE_SUB(CURDATE(),INTERVAL 7 day);
SET @sql = "select Log_Time as Log_Time_until,sum(DAU) as DAU,SUM(RechargeUserCnt) as APA,format(SUM(RechargeUserCnt)/sum(DAU)*100,2) as APA_DAU,sum(DNU) as DNU,sum(FirstRechargeUserCnt) as FirstRechargeUserCnt,format(sum(FirstRechargeUserCnt)/sum(DNU)*100,2) as FirstRechargeUserCnt_DNU,Sum(RechargeCnt) as RechargeCnt,Format(sum(RechargeDiamond)/10,2) as RechargeAmount,Format(sum(RechargeDiamond)/1.5,2) as RechargeAmount_tw,format(SUM(RechargeDiamond)/sum(DAU)/10,2) as ARPU,format(SUM(RechargeDiamond)/sum(DAU)/1.5,2) as ARPU_tw,format(SUM(RechargeDiamond)/sum(RechargeUserCnt)/10,2) as ARPPU,format(SUM(RechargeDiamond)/sum(RechargeUserCnt)/1.5,2) as ARPPU_tw ";
SET @channel_select = ',Channel_ID';
SET @channel_where = concat(' and Channel_ID in (', v_channel_id ,')');
SET @server_select = ',Server_ID';
SET @server_where = concat(' and Server_ID in (' , v_server_id , ')');
set @sql = CONCAT(@sql,' from (
select report_realtime.Log_Time,report_realtime.Server_ID,report_realtime.Channel_ID,DAU,DNU,RechargeUserCnt,FirstRechargeUserCnt,RechargeCnt,RechargeDiamond from (select Server_ID,Channel_ID,max(Log_Time) as max_time from report_realtime where 1=1 ');
set @sql = concat(@sql,@channel_where,@server_where);
select @sql;
set @sql2 := "group by Server_ID,Channel_ID)t1,report_realtime where t1.Server_ID = report_realtime.Server_ID and t1.Channel_ID = report_realtime.Channel_ID and t1.max_time = report_realtime.Log_Time)t2 ";
select @sql,@sql2,ifnull(@sql,""),ifnull(@sql2,""),concat(coalesce(@sql,""),coalesce(@sql2,"")),@sql;
end