简体   繁体   中英

Column Name ambiguously defined in code

I getting an error in the following code stating that column is ambiguously defined but i have already changed the name of the columns within each sub query. I am not sure where the error is coming from, if i run every sub query separately it works fine but can't seem to find the specific error line.

    With tskq as 
(
Select SFDC_D2C_TASKS.ACCOUNTID,
Count(SFDC_D2C_TASKS.ID) Total_Tasks,
(Case when Sum(Case when SFDC_D2C_TASKS.CREATED_BY_ROLE__C like '%OE%' then 1 End)>1 then 'True' else 'False' end) OE_Task,
(Case when Sum(Case when SFDC_D2C_TASKS.CREATED_BY_ROLE__C like '%CLOS%' then 1 End)>1 then 'True' else 'False' end) CLOS_Task
From SFDC_D2C_TASKS
Group by SFDC_D2C_TASKS.Accountid
Order by SFDC_D2C_TASKS.Accountid Desc
),
discntq as 
(
Select  
ACCOUNT__C as discnt_ACCOUNT,
Override_PRICE__C as discnt_Override_Price,
PARENT_PRODUCT_FAMILY__C as discntP_Prod_Fam,
PRODUCT_FAMILY__C as discnt_Prod_Fam,
ORDER_PRODUCT_TYPE__C as discnt_Ord_Prod_type,
QUANTITY__C as discnt_Qty,
PRICE__C as discnt_Price
from SFDC_D2C_ORDER_PRODUCT
where  PRODUCT_FAMILY__C like '%Discount%'
),
mgrq as
(
Select 
SFDC_D2C_ACCOUNT_OBJECT.OSM__C,
SFDC_D2C_USER.ID as USER_ID,
SFDC_D2C_USER.Name
from SFDC_D2C_ACCOUNT_OBJECT
Left Join SFDC_D2C_USER on SFDC_D2C_ACCOUNT_OBJECT.OSM__C= SFDC_D2C_USER.ID
),
accntq as 
(
Select
SFDC_D2C_ACCOUNT_OBJECT.ID as ACCOUNT_ID,
SFDC_D2C_ACCOUNT_OBJECT.CREATEDDATE as Account_Created_Date,
SFDC_D2C_ACCOUNT_OBJECT.BOOKING_DATE__C,
NVL(SFDC_D2C_ACCOUNT_OBJECT.ACCT_NUMBER__C,ACCOUNTNUMBER) as BAN,
SFDC_D2C_ACCOUNT_OBJECT.OWNERID,
SFDC_D2C_ACCOUNT_OBJECT.WEB_ID__C,
SFDC_D2C_ACCOUNT_OBJECT.ICI_CODE__C as Store_Code,
SFDC_D2C_ACCOUNT_OBJECT.COID__C,
SFDC_D2C_ACCOUNT_OBJECT.NAME as Customer_Name,
SFDC_D2C_ACCOUNT_OBJECT.OSM__C as OSM_ID,
SFDC_D2C_ACCOUNT_OBJECT.PROJECT_NAME__PC,
SFDC_D2C_ACCOUNT_OBJECT.TELUS_MANAGER__PC,
SFDC_D2C_ACCOUNT_OBJECT.D2C_ROLE__PC,
SFDC_D2C_ACCOUNT_OBJECT.SALESFORCE_USER__PC,
SFDC_D2C_ACCOUNT_OBJECT.OWNERID as Rep_ID,

   (Case 
        when SFDC_D2C_ACCOUNT_OBJECT.SALES_ACTIVITY__C in ('RMP', 'EDGE Collateral' , 'TAP' , 'MDU Lobby Event' , ' CityPlace') then 'MDU'
        else (
        case when SFDC_D2C_ACCOUNT_OBJECT.SALES_ACTIVITY__C in('Door Knocking' , 'Referral' , 'Mall Event' , 'Back to School' , 'Falcon') then ' D2C' end) 
   end) as D2C_Channel,

SFDC_D2C_ACCOUNT_OBJECT.RTCA_COMPLETE__C,
SFDC_D2C_ACCOUNT_OBJECT.SALES_ACTIVITY__C,
SFDC_D2C_ACCOUNT_OBJECT.ACTIVITY_DETAIL__C,
SFDC_D2C_ACCOUNT_OBJECT.SPECIALEVENT__C,
SFDC_D2C_ACCOUNT_OBJECT.GIFT_PRODUCT_NAME__C,
SFDC_D2C_ACCOUNT_OBJECT.ORDER_STATUS__C,
SFDC_D2C_ACCOUNT_OBJECT.BOOKED__C,
SFDC_D2C_ACCOUNT_OBJECT.CANCEL_ALL_PRODUCTS__C,
SFDC_D2C_ACCOUNT_OBJECT.LIVE_ORDER_ENTRY_STATUS__C,   
SFDC_D2C_ACCOUNT_OBJECT.TABLET_SUBMITTED_ORDER__C,
(Case when SFDC_D2C_ACCOUNT_OBJECT.BOOKING_DATE__C is not null then 'True' else 'False' end) as Softbooked
from SFDC_D2C_ACCOUNT_OBJECT
),
ordprdq as
(
Select
SFDC_D2C_ORDER_PRODUCT.ACCOUNT__C as ordpr_ACCOUNT,
 SFDC_D2C_ORDER_PRODUCT.CREATEDDATE as Order_Product_Created_Date,
 SFDC_D2C_ORDER_PRODUCT.BOOKED_DATE__C,
 SFDC_D2C_ORDER_PRODUCT.PRODUCT__C,
 SFDC_D2C_ORDER_PRODUCT.ORDER_PRODUCT_TYPE__C,
SFDC_D2C_ORDER_PRODUCT.PARENT_PRODUCT_FAMILY__C,
SFDC_D2C_ORDER_PRODUCT.PRODUCT_FAMILY__C,
SFDC_D2C_ORDER_PRODUCT.PRODUCT__C,
SFDC_D2C_ORDER_PRODUCT.QUANTITY__C,
 SFDC_D2C_ORDER_PRODUCT.STATUS__C,
SFDC_D2C_ORDER_PRODUCT.STATUS_REASON__C,
 SFDC_D2C_ORDER_PRODUCT.MIGRATION__C
From  SFDC_D2C_ORDER_PRODUCT
),
prdctq as
(
Select
SFDC_D2C_PRODUCTS.ID as Product_ID, 
SFDC_D2C_PRODUCTS.ACTIVE__C,
SFDC_D2C_PRODUCTS.PRICE__C
From SFDC_D2C_PRODUCTS
)

Select 
accntq.ACCOUNT_ID
From accntq
Left Join ordprdq on accntq.ACCOUNT_ID =ordprdq.ordpr_ACCOUNT 
Left Join ordprdq on prdctq.Product_ID=ordprdq.PRODUCT__C
Left Join mgrq on mgrq.ACCOUNT_ID=accntq.OSM__C
Left Join tskq on taskq.ACCOUNT__C= accntq.ACCOUNT_ID

您的ordprdq CTE在其选择列表中两次包含SFDC_D2C_ORDER_PRODUCT.PRODUCT__C

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM