我在以下代码中收到错误,指出该列的含义模糊,但我已经更改了每个子查询中列的名称。我不确定错误来自哪里,如果我单独运行每个子查询它工作正常但似乎无法找到特定的错误行。
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
答案 0 :(得分:3)
您的ordprdq
CTE在其选择列表中包括SFDC_D2C_ORDER_PRODUCT.PRODUCT__C
两次。