父格sql的解析
SELECT XCPX,XCPDL ,XCPZL FROM (SELECT DISTINCT XCPX,XCPDL,XCPZL FROM XPCXP_YS
WHERE BM IN('经销商业务部','兴客坊')
UNION(SELECTDISTINCT A.CPX AS XCPX,A.CPDL AS XCPDL,A.CPZL AS XCPZLFROM SYS.ORDER_SALE@ZJK BJOIN KHFL_LS L1ON L1.KSBM=B.CUSTCODELEFT JOIN CPFL_LS AON A.INVNAME=B.INVNAMEWHERE L1.BM2022='经销商业务部'AND B.DBILLDATE >=TO_DATE('${KSRQ}','YYYY-MM-DD')AND B.DBILLDATE <= TO_DATE('${D}','YYYY-MM-DD') --这部分union是因为有些没预算的品类也展示出来了需要统计,把预算目标金额设为0即可
UNION (SELECT
DISTINCT A.CPX AS XCPX,A.CPDL AS XCPDL, A.CPZL AS XCPZLFROM SYS.ORDER_FPMX@ZJK BJOIN KHFL_LS L1ON L1.KSBM = B.CUSTCODELEFT JOIN CPFL_LS AON A.INVNAME = B.INVNAMEWHERE L1.BM2022 = '经销商业务部'AND B.DBILLDATE >= TO_DATE('${KSRI}', 'YYYY-MM-DD')AND B.DBILLDATE <= TO_DATE('${JSRI}', 'YYYY-MM-DD')
)--这部分union是因为))
WHERE 1=1${if(LEN(产品类别)=0,""," and XCPDL='"+产品类别+"'")}
分为三部分原始部分和union的是订单里经销商业务部的所有品类第二部分是同期发票里的所有品类。