列名重复(SQL Developer)

时间:2019-01-02 04:21:04

标签: sql oracle oracle11g

每次我想过滤一列以查找某个值时,都会出现此错误:

IMAGE

我的查询工作正常,但无法正常工作。

这是我的查询

SELECT
    hp.party_name                              
  , hca.account_number
  , hca.cust_account_id                        
 -- , hcsu.LOCATION customer_site_name
  , hcas.cust_acct_site_id                     
  , hcp.phone_number
  , hcp.email_address
  , CASE WHEN LENGTH(hcp.phone_number) > 25 then null else hcp.phone_number END
  , hl.address1
  , hl.address2
  , hl.address3
  , hl.address4
  , hl.city
  , hl.province
  , hl.postal_code
  , hcas.status                                
  , DECODE( hcas.attribute5, 'PUP', 'Y', 'N' ) 
  , hca.status                                 
FROM apps.hz_cust_accounts hca
INNER JOIN apps.hz_cust_acct_sites_all hcas ON hca.cust_account_id = hcas.cust_account_id
INNER JOIN apps.hz_party_sites hps ON hcas.party_site_id = hps.party_site_id
INNER JOIN apps.hz_locations hl ON hps.location_id = hl.location_id
INNER JOIN apps.hz_parties hp ON hps.party_id = hp.party_id
LEFT JOIN (
        SELECT
            owner_table_id
          , max(case when contact_point_type = 'PHONE' then phone_number end) phone_number
          , max(case when contact_point_type = 'EMAIL' then email_address end) email_address
        FROM hz_contact_points
        WHERE status = 'A'
        AND primary_flag = 'Y'
        AND owner_table_name = 'HZ_PARTY_SITES'
        AND contact_point_type IN ('EMAIL','PHONE')
        GROUP BY 
            owner_table_id
    ) hcp ON hcas.party_site_id = hcp.owner_table_id 
WHERE hcas.status = 'A'
AND hps.status = 'A'
AND hca.status = 'A'
AND hca.account_number = ''
;

我尝试解决这个问题没有成功。

你能帮我吗?

PS:我正在使用SQL DEVELOPER和oracle数据库

1 个答案:

答案 0 :(得分:1)

您可以在下面尝试使用别名作为列名

SELECT
    hp.party_name                              
  , hca.account_number
  , hca.cust_account_id                        
 -- , hcsu.LOCATION customer_site_name
  , hcas.cust_acct_site_id                     
  , hcp.phone_number
  , hcp.email_address
  , CASE WHEN LENGTH(hcp.phone_number) > 25 then null else hcp.phone_number END
  , hl.address1
  , hl.address2
  , hl.address3
  , hl.address4
  , hl.city
  , hl.province
  , hl.postal_code
  , hcas.status  as hcas_status                               
  , DECODE( hcas.attribute5, 'PUP', 'Y', 'N' ) 
  , hca.status  as hca_status                             
FROM apps.hz_cust_accounts hca
INNER JOIN apps.hz_cust_acct_sites_all hcas ON hca.cust_account_id = hcas.cust_account_id
INNER JOIN apps.hz_party_sites hps ON hcas.party_site_id = hps.party_site_id
INNER JOIN apps.hz_locations hl ON hps.location_id = hl.location_id
INNER JOIN apps.hz_parties hp ON hps.party_id = hp.party_id
LEFT JOIN (
        SELECT
            owner_table_id
          , max(case when contact_point_type = 'PHONE' then phone_number end) phone_number
          , max(case when contact_point_type = 'EMAIL' then email_address end) email_address
        FROM hz_contact_points
        WHERE status = 'A'
        AND primary_flag = 'Y'
        AND owner_table_name = 'HZ_PARTY_SITES'
        AND contact_point_type IN ('EMAIL','PHONE')
        GROUP BY 
            owner_table_id
    ) hcp ON hcas.party_site_id = hcp.owner_table_id 
WHERE hcas.status = 'A'
AND hps.status = 'A'
AND hca.status = 'A'
AND hca.account_number = ''
;