CREATE DEFINER=`tft`@`%` PROCEDURE `sp_mp_accountDetail_list`(in cosmosPassportId char(32),in cpId char(32),
in tName varchar(64),in tradeType int)
BEGIN
set @cpId=cpId;
set @aId=FN_GET_ACCOUNTID(@cpId);
-- select create_time,gb_orderno,pay_no,place,trade_type,get_money,pay_money,balance,note
 -- from tb_mp_accountdetail where email=FN_GET_EMAIL(@cpId) order by create_time desc; 
if tradeType=2 then 
set @ql =' and (FN_GET_PAYTYPE(@aId,p.id)=0 or FN_GET_PAYTYPE(@aId,p.id)=1) ';
elseif tradeType=1 then 
set @ql =' and FN_GET_PAYTYPE(@aId,p.id)=1 ';
else 
set @ql =' and FN_GET_PAYTYPE(@aId,p.id)=0 ';
end if;


set @listSql=CONCAT('select p.id,p.create_time,p.pay_no,FN_GET_PAYTYPE(@aId,p.id) as isTZ,
  p.payer_realName as prn,p.getter_realName as grn,p.pay_money,p.stage 
  from tb_mp_pay as p left join tb_mp_order as o 
  on p.order_no=o.order_no
  where (p.payer_id=@aId or p.getter_id=@aId)
  ',@ql,' order by p.create_time desc');
prepare _stmt from @listSql;
execute _stmt;
deallocate prepare _stmt;
END$$如图红色处,,,,,判断的条件有3种可能,
FN_GET_PAYTYPE(@aId,p.id)=0
FN_GET_PAYTYPE(@aId,p.id)=1
(FN_GET_PAYTYPE(@aId,p.id)=1 or FN_GET_PAYTYPE(@aId,p.id)=0)
个人感觉这么写有点弱智,,,,,

解决方案 »

  1.   


        if tradeType=2 then 
            set @ql =' and (FN_GET_PAYTYPE(@aId,p.id)=0 or FN_GET_PAYTYPE(@aId,p.id)=1) ';
        elseif tradeType=1 then 
            set @ql =' and FN_GET_PAYTYPE(@aId,p.id)=1 ';
        else 
            set @ql =' and FN_GET_PAYTYPE(@aId,p.id)=0 ';
        end if;
    就是这一处,能正常运行,个人感觉不是最优的,,,,,
      

  2.   

    虽然这段     if tradeType=2 then 
            set @ql =' and (FN_GET_PAYTYPE(@aId,p.id)=0 or FN_GET_PAYTYPE(@aId,p.id)=1) ';
        elseif tradeType=1 then 
            set @ql =' and FN_GET_PAYTYPE(@aId,p.id)=1 ';
        else 
            set @ql =' and FN_GET_PAYTYPE(@aId,p.id)=0 ';
        end if;
    可以用下面 
    set @ql =concat(' and (FN_GET_PAYTYPE(@aId,p.id)&',tradeType+1,') ');来替代,但如果是我自己,还是会用你现在的方法,比较容易读懂逻辑。