我的任务是重建从oracle 11g数据库到MSSQL 2008数据库的视图。我在重新创建这个视图时陷入困境:在oracle中它是这样的:
CREATE OR REPLACE VIEW TRANSACTION_VIEW
(FCT_TM_SOL_ID, FCT_TM_ACID, FCT_TM_RCRE_USER_ID, FCT_TM_TRAN_TYPE,
FCT_TM_TRAN_SUB_TYPE,DA_SCHM_CODE,DC_GENDER,DC_CUST_TYPE_CODE,DA_ACCT_MGR_ID
)
AS
SELECT FCT_TM_SOL_ID,FCT_TM_ACID
,FCT_TM_RCRE_USER_ID,FCT_TM_TRAN_TYPE,FCT_TM_TRAN_SUB_TYPE,dim_account.DA_SC
HM_CODE,
DC_GENDER,DC_CUST_TYPE_CODE,DA_ACCT_MGR_ID
FROM FACT_TRANSACTION ,dim_account,dim_customer
WHERE FCT_TM_ACID = dim_account.DA_ACID(+)
and dim_account.DA_CUST_ID = dim_customer.DC_CUST_ID(+)
and dim_account.DA_ACCT_OWNERSHIP ='C';
FACT_TRANSACTION
和dim_customer
之间没有直接关系,因此在MSSQL中重新创建视图时我得到了Stuck。到目前为止,我有:
CREATE VIEW TRANSACTION_VIEW
(FCT_TM_SOL_ID, FCT_TM_ACID, FCT_TM_RCRE_USER_ID, FCT_TM_TRAN_TYPE,
FCT_TM_TRAN_SUB_TYPE,DA_SCHM_CODE,DC_GENDER,DC_CUST_TYPE_CODE,DA_ACCT_MGR_ID
)
AS
SELECT t1.FCT_TM_SOL_ID,t1.FCT_TM_ACID
,t1.FCT_TM_RCRE_USER_ID,t1.FCT_TM_TRAN_TYPE,t1.FCT_TM_TRAN_SUB_TYPE,t2.DA_SCHM_CODE,
t3.DC_GENDER,t3.DC_CUST_TYPE_CODE,t3.DA_ACCT_MGR_ID
FROM FACT_TRANSACTION t1
left join dim_account t2 on t1.FCT_TM_ACID = t2.DA_ACID
left join ---STUCK HERE dim_customer t3
where t2.DA_ACCT_OWNERSHIP ='C';
请帮助您了解如何加入不相关的实体。
答案 0 :(得分:1)
虽然FACT_TRANSACTION
和dim_customer
之间没有直接关系,但它们在dim_account
中确实有共同点(尽管是不同的字段)。因此,您可以在dim_account
和dim_customer
之间进行第二次左连接:
SELECT t1.FCT_TM_SOL_ID,t1.FCT_TM_ACID, t1.FCT_TM_RCRE_USER_ID,t1.FCT_TM_TRAN_TYPE,t1.FCT_TM_TRAN_SUB_TYPE,t2.DA_SCHM_CODE,
t3.DC_GENDER,t3.DC_CUST_TYPE_CODE,t3.DA_ACCT_MGR_ID
FROM FACT_TRANSACTION t1
left join dim_account t2 on t1.FCT_TM_ACID = t2.DA_ACID
left join dim_customer t3 on t2.DA_CUST_ID = t3.DC_CUST_ID
where t2.DA_ACCT_OWNERSHIP ='C';