是不是语句有问题呢? 按理说left join是以A表为准吧? 目前A表和C表的日期确实是没有相等的. 但我希望用户在查询时,如果A表字段有值就显示, C表字段没值就显示为空。 而不是因为A和C表关联时因为日期条件,4张表的字段都不显示值。 语句: SELECT SUM(ZIFXAV012),SUM(ZIFXAV015),SUM(ZIFXAC016), SUM(QMKC)AS QMKC,SUM(AMOUNT)AS AMOUNT,ZICZS0006,EMPLGROUP, BALANCE,ZPROFIT,CALMONTH,GL_ACCOUNT FROM ( SELECT A.ZIFXAV012,A.ZIFXAV015,A.ZICZS0006,BALANCE,A.ZPROFIT,A.CALMONTH,A.ZIFXAC016, B.GL_ACCOUNT,D.QMKC,C.AMOUNT,C.EMPLGROUP FROM "_SYS_BIC"."CB.AL.YW/ZAL_SALES_DETAIL" A LEFT JOIN "_SYS_BIC"."CB.BL.YW/ZBL_ZDEFI002" B ON A.ZPROFIT = B.ZPROFIT AND A.CALMONTH = B.CALMONTH LEFT JOIN "_SYS_BIC"."CB.BL.YW/ZBL_ZDEYG006" C ON SUBSTR(B.ZPROFIT,2,20)=SUBSTR(C.MAST_CCTR ,2,20) AND A.CALMONTH = C.CALMONTH LEFT JOIN (SELECT ZICZS0000,CALMONTH,SUM(DMBTR_TO) AS QMKC FROM ( SELECT CALMONTH,ZICZS0000,DMBTR_TO -- 期末金额 FROM "_SYS_BIC"."CB.AL.YW/ZAL_STOCK_BQPRICE" (PLACEHOLDER."$$ZIP_STDATE$$"=> '20220701', -- 时段开始日期 PLACEHOLDER."$$ZIP_ENDDATE$$"=>'20220731') -- 时段结束日期 WHERE ZICZA0001 NOT IN ('Z005','Z006','Z008','Z010') -- 排除虚拟商品等 AND ZICZA0003 NOT IN ('1110') -- 排除以旧换新旧饰 AND ZICZA0004 IN ('D01','D02','D03','D04','D05','D06','D07','D08','D09') ) GROUP BY ZICZS0000,CALMONTH) D ON CONCAT('P',D.ZICZS0000)=A.ZPROFIT WHERE FISCPER NOT LIKE '%000' AND B.ZPROFIT NOT LIKE 'P7%' AND C.WAGETYPE='/559' AND A.CALMONTH>= '202207' AND A.CALMONTH<= '202207' ORDER BY A.ZIFXAV012,A.ZIFXAV015,ZICZS0006,BALANCE,A.ZPROFIT,A.CALMONTH, A.ZIFXAC016,B.GL_ACCOUNT,D.QMKC,C.AMOUNT,C.EMPLGROUP) GROUP BY ZPROFIT,CALMONTH,ZIFXAV012, ZIFXAV015,ZIFXAC016,ZICZS0006,BALANCE,GL_ACCOUNT,QMKC,AMOUNT,EMPLGROUP ------------------------------------------------------------------------------ 截图: |