客户相关数据sql

客户table比较复杂,特别是联系人 电话 税分类

select distinct hps.party_id,
       hp.party_number,
       hp.party_name,
       hca.account_number,
       hca.status,
       hcasa.status,
       hps.party_site_id,
       hps.party_site_number,  --地点编码
       hcsua.site_use_code,--地址用途
       hl.location_id,
       hl.country,
       hl.city,
       hl.address1,
       hl.address2,
       hl.address3,
       hl.address4,
       hcsua.cust_acct_site_id,
       (SELECT rtt.NAME
          FROM ra_terms_tl RTT
         WHERE hcsua.payment_term_id = rtt.TERM_ID
           and rtt.language = 'ZHS') NAME,--付款条件
       HPER.PARTY_NAME PERSON,--联系人
       HCP.Raw_Phone_Number ,--联系人电话
        hcsua.tax_reference,--纳税登记编号
        hcsua.tax_code,--税分类
        bank.party_name,--银行
        branch.party_name,--分行
        ieba.bank_account_num--账户
  from hz_cust_accounts       hca,
       hz_cust_site_uses_all  hcsua,
       hz_cust_acct_sites_all hcasa,
       hz_party_sites         hps,
       hz_locations           hl,
       hz_parties             hp,
       hz_customer_profiles   hcp,
       hz_cust_account_roles hcar,
       hz_relationships      hr,
       hz_parties            HPER,
       HZ_CONTACT_POINTS     HCP,
       iby_account_owners iao,
       iby_ext_bank_accounts ieba,
       hz_parties            bank,
       hz_parties            branch
 where hcsua.cust_acct_site_id = hcasa.cust_acct_site_id
   AND hcasa.party_site_id = hps.party_site_id
   and hp.party_id = hca.party_id
   and hca.cust_account_id = hcasa.cust_account_id
   AND hl.location_id = hps.location_id
   and hps.party_id = hp.party_id
   and hp.party_id = iao.account_owner_party_id(+)
   and iao.ext_bank_account_id = ieba.ext_bank_account_id(+)
   and ieba.bank_id = bank.party_id(+)
   and bank.party_type(+) = 'ORGANIZATION'
   and ieba.branch_id = branch.party_id(+)
   and branch.party_type(+) = 'ORGANIZATION'
   and hca.cust_account_id = hcp.cust_account_id
   and hcasa.cust_acct_site_id = hcsua.cust_acct_site_id
   and hcar.cust_acct_site_id(+) = hcsua.cust_acct_site_id
   and hcar.party_id = hr.party_id(+)
   and hcar.role_type(+) = 'CONTACT'
   AND HCAR.STATUS(+) = 'A'
   AND HR.SUBJECT_TYPE(+) = 'PERSON'
   AND HR.SUBJECT_ID = HPER.PARTY_ID(+)
   AND HCAR.PARTY_ID = HCP.OWNER_TABLE_ID(+)
   AND HCP.owner_table_name(+) = 'HZ_PARTIES'
   and hcp.contact_point_type(+) = 'PHONE'
      --and hp.party_id = 3080
 --  and hp.party_name = 'xx'
-- and ooh.order_number = '50064'

你可能感兴趣的:(OM,Technicals,数据库,oracle)