有关SQL的数据问题

时间:2018-06-28 19:00:36

标签: sql oracle

我无法仅获取BUY参数的数据。 SEL参数工作正常。可能是联接的问题。

SELECT DISTINCT
    RP.RP_RECORD_ID,
    RP.RATE_PROFILE_NAME, 
    RPH.RATE_TYPE, 
    RPH.CHARGE_CODE, 
    RPH.TRANSPORT_MODE, 
    RPH.PLACE_OF_RECEIPT_CODE, 
    (SELECT CD_DESCRIPTION FROM CODE_DETAIL 
     WHERE CM_CODE ='145' AND CD_CODE = RPH.ORIGIN_TYPE), 
    DECODE(RPH.ORIGIN_TYPE, 'PO', RPH.ORIGIN_PORT_CODE, 'CNT' , ORIGIN_COUNTRY_CODE, 'A', ORIGIN_AREA_CODE, 'CIT', CITY_ORIGIN, 'PV', RPH.ORIGIN_REGION_CODE) ORIGIN,
    RPH.PLACE_OF_DELIVERY_CODE,  
    RPH.CARRIER_CODE, 
    PCP.PARTNER_ID, 
    PARTNER.PARTNER_NAME, 
    COM.COMMODITY_DESCRIPTION, 
    RPH.REMARK, RPH.RPH_RECORD_ID,
    RPH.ORIGIN_TYPE, RPH.DESTINATION_TYPE,
    (SELECT DISTINCT EMP.employee_name                             
     FROM partner PAR, employee EMP, partner_relationships PRE 
     WHERE PARTNER.partner_id = PAR.partner_id 
       AND PAR.partner_id = PRE.partner_id 
       AND PRE.EMPLOYEE_NO = EMP.EMPLOYEE_NO 
       AND PRE.transport_mode = RPH.transport_mode 
       AND (PRE.IMPORT_EXPORT_IND IS NULL OR    -- ' Start of New code by SB on 16-FEB-2010 for WHD136784
            PRE.IMPORT_EXPORT_IND = (CASE 
                                        WHEN (RPH.City_Origin = 'VNSGN' OR rph.origin_country_code ='VN' OR rph.origin_port_code ='VN' OR RPH.origin_port_code = 'VNSGN') 
                                           THEN 'E' 
                                        WHEN (RPH.City_Dest = 'VNSGN' OR RPH.dest_country_code = 'VN' OR RPH.dest_port_code = 'VNSGN' OR  RPH.dest_port_code = 'VNSGN') 
                                           THEN 'I' 
                                        ELSE '' 
                                   END))        --  'End of New code by SB on 16-FEB-2010 for WHD136784
       AND PRE.company_id = CP.company_id 
       AND rownum = 1) salesman,                            --   'End of WHD136784 new code
      RPH.RPH_RECORD_ID, RPH.CURRENCY_CODE 
  FROM
      RATE_PROFILE RP, RATE_PROFILE_HEADER RPH, 
      PARTNER_CHARGE_PROFILE PCP,  PARTNER , 
      COMMODITY_CODES com, OFFICES,  
      company_partners CP 
  WHERE
      RP.RP_RECORD_ID =  RPH.RP_RECORD_ID 
      AND PCP.PARTNER_ID = PARTNER.PARTNER_ID 
      AND RPH.COMMCODE_RECORD_ID = COM.CC_RECORD_ID(+) 
      AND PCP.COMPANY_ID = OFFICES.COMPANY_ID 
      AND OFFICES.OFFICE_TYPE = 'T' 
      AND partner.partner_id = CP.partner_id             
      AND CP.COMPANY_ID = '{?CompanyID}'             
      AND CP.company_id = PCP.company_id 
      AND PCP.charge_code = RPH.Charge_code    
      AND (('&psRate_type') = 'SEL' AND  PCP.charge_calculation_method = 'R' AND RPH.RP_RECORD_ID = PCP.CHARGE_RATEPROF_RECORD_ID
      OR
           ('&psRate_type') = 'BUY' AND  PCP.cost_calculation_method = 'R' AND RPH.RP_RECORD_ID = PCP.COST_RATEPROF_RECORD_ID)
       )

“ SEL”参数的数据即将到来,但“ BUY”数据的获取0条记录。 我检查了联接的所有内容,但无法找出问题所在。 在where子句中AND AND条件没有问题。

请提出建议

1 个答案:

答案 0 :(得分:0)

我已使用以下加入条件解决了此问题:

(RPH.RP_RECORD_ID = PCP.CHARGE_RATEPROF_RECORD_ID OR RPH.RP_RECORD_ID = PCP.COST_RATEPROF_RECORD_ID)