某一个OU下只有收单地点、只有收货方和收单收货方的所有客户

某一个OU下只有收单地点的SQL:

 

SELECT hou.name org_name, hp.party_name customer_name, hp.party_number customer_number, bill_to_cust.cust_acct_site_id cust_acct_site_id, hps.party_site_id party_site_id, hps.party_site_number party_site_number, hca.account_number account_number FROM ar.hz_cust_accounts hca, hr_operating_units hou, hz_parties hp, hz_party_sites hps, (SELECT bill_cust.cust_account_id cust_account_id, bill_cust.cust_acct_site_id cust_acct_site_id, bill_cust.party_site_id party_site_id, bill_cust.org_id org_id FROM (SELECT hcasa.cust_account_id cust_account_id, hcasa.cust_acct_site_id cust_acct_site_id, hcasa.party_site_id party_site_id, bill.org_id FROM hz_cust_acct_sites_all hcasa, (SELECT hcsua.cust_acct_site_id cust_acct_site_id, hcsua.org_id org_id FROM hz_cust_site_uses_all hcsua WHERE hcsua.site_use_code = 'BILL_TO' AND hcsua.status = 'A') bill WHERE hcasa.cust_acct_site_id = bill.cust_acct_site_id AND hcasa.org_id = bill.org_id AND NOT EXISTS (SELECT hcasa.cust_account_id, hcasa.party_site_id party_site_id, cust_site.org_id FROM hz_cust_acct_sites_all cust_site, hz_cust_site_uses_all hcsua WHERE hcsua.cust_acct_site_id = cust_site.cust_acct_site_id AND cust_site.cust_account_id = hcasa.cust_account_id AND cust_site.org_id = hcasa.org_id AND hcsua.site_use_code = 'SHIP_TO' AND hcsua.status = 'A')) bill_cust) bill_to_cust WHERE hp.party_id = hca.party_id AND hca.cust_account_id = bill_to_cust.cust_account_id AND hou.organization_id = bill_to_cust.org_id AND bill_to_cust.party_site_id = hps.party_site_id AND hca.status = 'A' ORDER BY customer_name, org_name;

某一个OU下只有收货地点的SQL:

SELECT hou.name org_name, hp.party_name customer_name, hp.party_number customer_number, ship_to_cust.cust_acct_site_id cust_acct_site_id, hps.party_site_id party_site_id, hps.party_site_number party_site_number, hca.account_number account_number FROM ar.hz_cust_accounts hca, hr_operating_units hou, hz_parties hp, hz_party_sites hps, (SELECT ship_cust.cust_account_id cust_account_id, ship_cust.cust_acct_site_id cust_acct_site_id, ship_cust.party_site_id party_site_id, ship_cust.org_id org_id FROM (SELECT hcasa.cust_account_id cust_account_id, hcasa.cust_acct_site_id, hcasa.party_site_id, ship.org_id FROM hz_cust_acct_sites_all hcasa, (SELECT hcsua.cust_acct_site_id cust_acct_site_id, hcsua.org_id org_id FROM hz_cust_site_uses_all hcsua WHERE hcsua.site_use_code = 'SHIP_TO' AND hcsua.status = 'A') ship WHERE hcasa.cust_acct_site_id = ship.cust_acct_site_id AND hcasa.org_id = ship.org_id AND NOT EXISTS (SELECT hcasa.cust_account_id, cust_site.org_id FROM hz_cust_acct_sites_all cust_site, hz_cust_site_uses_all hcsua WHERE hcsua.cust_acct_site_id = cust_site.cust_acct_site_id AND cust_site.cust_account_id = hcasa.cust_account_id AND hcasa.org_id = cust_site.org_id AND hcsua.site_use_code = 'BILL_TO' AND hcsua.status = 'A')) ship_cust) ship_to_cust WHERE hp.party_id = hca.party_id AND hca.cust_account_id = ship_to_cust.cust_account_id AND hou.organization_id = ship_to_cust.org_id AND ship_to_cust.party_site_id = hps.party_site_id AND hca.status = 'A' ORDER BY hp.party_name, hou.name;

某一个OU下既有收单地点又有收货地点的SQL:

SELECT hou.name org_name, hp.party_name customer_name, hp.party_number customer_number, hcasa.cust_acct_site_id cust_acct_site_id, hcasa.party_site_id party_site_id, hps.party_site_number party_site_number, hca.account_number account_number FROM ar.hz_cust_accounts hca, hr_operating_units hou, hz_parties hp, hz_party_sites hps, hz_cust_acct_sites_all hcasa WHERE hp.party_id = hca.party_id AND hcasa.cust_account_id = hca.cust_account_id AND hou.organization_id = hcasa.org_id AND hcasa.party_site_id = hps.party_site_id AND hca.status = 'A' MINUS SELECT hou.name org_name, hp.party_name customer_name, hp.party_number customer_number, bill_to_cust.cust_acct_site_id cust_acct_site_id, hps.party_site_id party_site_id, hps.party_site_number party_site_number, hca.account_number account_number FROM ar.hz_cust_accounts hca, hr_operating_units hou, hz_parties hp, hz_party_sites hps, (SELECT bill_cust.cust_account_id cust_account_id, bill_cust.cust_acct_site_id cust_acct_site_id, bill_cust.party_site_id party_site_id, bill_cust.org_id org_id FROM (SELECT hcasa.cust_account_id cust_account_id, hcasa.cust_acct_site_id cust_acct_site_id, hcasa.party_site_id party_site_id, bill.org_id FROM hz_cust_acct_sites_all hcasa, (SELECT hcsua.cust_acct_site_id cust_acct_site_id, hcsua.org_id org_id FROM hz_cust_site_uses_all hcsua WHERE hcsua.site_use_code = 'BILL_TO' AND hcsua.status = 'A') bill WHERE hcasa.cust_acct_site_id = bill.cust_acct_site_id AND hcasa.org_id = bill.org_id AND NOT EXISTS (SELECT hcasa.cust_account_id, hcasa.party_site_id party_site_id, cust_site.org_id FROM hz_cust_acct_sites_all cust_site, hz_cust_site_uses_all hcsua WHERE hcsua.cust_acct_site_id = cust_site.cust_acct_site_id AND cust_site.cust_account_id = hcasa.cust_account_id AND cust_site.org_id = hcasa.org_id AND hcsua.site_use_code = 'SHIP_TO' AND hcsua.status = 'A')) bill_cust) bill_to_cust WHERE hp.party_id = hca.party_id AND hca.cust_account_id = bill_to_cust.cust_account_id AND hou.organization_id = bill_to_cust.org_id AND bill_to_cust.party_site_id = hps.party_site_id AND hca.status = 'A' MINUS SELECT hou.name org_name, hp.party_name customer_name, hp.party_number customer_number, ship_to_cust.cust_acct_site_id cust_acct_site_id, hps.party_site_id party_site_id, hps.party_site_number party_site_number, hca.account_number account_number FROM ar.hz_cust_accounts hca, hr_operating_units hou, hz_parties hp, hz_party_sites hps, (SELECT ship_cust.cust_account_id cust_account_id, ship_cust.cust_acct_site_id cust_acct_site_id, ship_cust.party_site_id party_site_id, ship_cust.org_id org_id FROM (SELECT hcasa.cust_account_id cust_account_id, hcasa.cust_acct_site_id, hcasa.party_site_id, ship.org_id FROM hz_cust_acct_sites_all hcasa, (SELECT hcsua.cust_acct_site_id cust_acct_site_id, hcsua.org_id org_id FROM hz_cust_site_uses_all hcsua WHERE hcsua.site_use_code = 'SHIP_TO' AND hcsua.status = 'A') ship WHERE hcasa.cust_acct_site_id = ship.cust_acct_site_id AND hcasa.org_id = ship.org_id AND NOT EXISTS (SELECT hcasa.cust_account_id, cust_site.org_id FROM hz_cust_acct_sites_all cust_site, hz_cust_site_uses_all hcsua WHERE hcsua.cust_acct_site_id = cust_site.cust_acct_site_id AND cust_site.cust_account_id = hcasa.cust_account_id AND hcasa.org_id = cust_site.org_id AND hcsua.site_use_code = 'BILL_TO' AND hcsua.status = 'A')) ship_cust) ship_to_cust WHERE hp.party_id = hca.party_id AND hca.cust_account_id = ship_to_cust.cust_account_id AND hou.organization_id = ship_to_cust.org_id AND ship_to_cust.party_site_id = hps.party_site_id AND hca.status = 'A' ORDER BY customer_name, org_name;

你可能感兴趣的:(sql,HP)