小白不白(提问者)with a as (select t1.*,t2.name from fr_qdkc_tb t1
left join bd_psndoc_new t2
on t1.tbr=t2.code
union all
select t1.*,t3.user_name from fr_qdkc_tb t1
left join dw_zt_sx_xhgwda t3
on t1.tbr=t3.user_code
)
select distinct * from a
where name is not NULL
and org_code in (\'${ORG_NAME}\')
and month=\'${mon}\'
${if(len(pq) == 0,\"\",\"and pqname in (\'\" + pq + \"\')\")}
${if(len(kh) == 0,\"\",\"and customer_name in (\'\" + kh + \"\')\")}
${if(len(qd) == 0,\"\",\"and customer_qd in (\'\" + qd + \"\')\")}
${if(len(xh) == 0,\"\",\"and xh in (\'\" + xh + \"\')\")}
order by tbsj DESC