mssql and left join duplicate records

前端 未结 3 967
长情又很酷
长情又很酷 2021-01-28 23:03

Original Query

SELECT DISTINCT
      IP.op_code as ip_op_code,
      IPH.op_code as iph_op_code,
      debt_trans.tx_amount as cash,
      DT.tx_amount as revenu         


        
3条回答
  •  旧时难觅i
    2021-01-28 23:29

    looking to your data could you join must match also for op_code AND instplanheader.op_code = instplan.op_code

    $sql = "SELECT DISTINCT
          instplan.debt_code,
          instplan.op_code,
          instplanheader.op_code as plan_op,
          instplan.ipactualpaymentamt
        FROM instplanheader
        LEFT JOIN instplan ON instplanheader.debt_code=instplan.debt_code
    
            AND instplanheader.op_code = instplan.op_code 
    
            AND instplan.tran_code NOT IN ('DR3001','DR3002','DR3003','DR3004')
            AND instplan.ipactualpaymentamt > 0.00
            AND instplan.ipactualpaymentdt >= '2019-02-04' AND instplan.ipactualpaymentdt <= '2019-02-04'
              AND instplanheader.iphcreationdate >= '2018-12-01' AND instplanheader.iphcreationdate <= '2019-02-04'
        ";
    

提交回复
热议问题