mysql 存储过程
BEGIN DECLARE result DOUBLE default 0 ; DECLARE startdata Date; declare enddata Date;
select round(sum(c.price/c.days_*c.act_day),2) from (select a.*, if(date_format(if(a.start_date<=b.startdata,b.startdata,a.start_date),"%Y-%m-%d")=date_format(if(a.end_date<=b.enddata,a.end_date,b.enddata),"%Y-%m-%d"), 1, (DATEDIFF(if(a.end_date<=b.enddata,a.end_date,b.enddata),if(a.start_date<=b.startdata,b.startdata,a.start_date)))+1) as act_day from (SELECT csid, start_date, end_date, (DATEDIFF( end_date, start_date )+1)days_, order_amount AS price FROM pay_vip_record where csid in(select id from um_consumer where del_flag=0 and phone_no="xxxxxxxxxx"))a, (select '2017-09-01' startdata,'2017-09-01' enddata)b)c where c.act_day>0; END
select round(sum(c.price/c.days_*c.act_day),2) from (select a.*, if(date_format(if(a.start_date<=b.startdata,b.startdata,a.start_date),"%Y-%m-%d")=date_format(if(a.end_date<=b.enddata,a.end_date,b.enddata),"%Y-%m-%d"), 1, (DATEDIFF(if(a.end_date<=b.enddata,a.end_date,b.enddata),if(a.start_date<=b.startdata,b.startdata,a.start_date)))+1) as act_day from (SELECT csid, start_date, end_date, (DATEDIFF( end_date, start_date )+1)days_, order_amount AS price FROM pay_vip_record where csid in(select id from um_consumer where del_flag=0 and phone_no="xxxxxxxxxx"))a, (select '2017-09-01' startdata,'2017-09-01' enddata)b)c where c.act_day>0; END
 
                    
                     
                    
                 
                    
                
 
                
            
         
         浙公网安备 33010602011771号
浙公网安备 33010602011771号