此Access连接查询如何在Teradata中工作?

时间:2017-08-29 18:38:48

标签: join inner-join teradata correlated-subquery

我试图在Teradata中确定此查询的等效版本。我遇到的主要问题是试图找到一种方法,使用两个不同的密钥(package_unit_id和retail_unit_id)两次加入同一列。在Access中,我能够分配一个别名,允许我选择tbleDIRGA_ItemUnit.Unit_Name列两次。这在Teradata中如何运作?如果我不清楚,请告诉我。

在Microsoft Access中:

SELECT 

    tblDIRGA_Item.SubTeam_No, 
    tblDIRGA_ItemIdentifier.Identifier, 
    tblDIRGA_ItemUnit.Unit_Name AS PackUOM,
    tblDIRGA_ItemUnit_1.Unit_Name AS RetailUOM

FROM (((tblDIRGA_ItemIdentifier AS tblDIRGA_ItemIdentifier_1 

INNER JOIN tblDIRGA_Item 
ON tblDIRGA_ItemIdentifier.Item_Key = tblDIRGA_Item.Item_Key)

INNER JOIN tblDIRGA_ItemUnit 
ON tblDIRGA_Item.Package_Unit_ID = tblDIRGA_ItemUnit.Unit_ID) 

INNER JOIN tblDIRGA_ItemUnit AS tblDIRGA_ItemUnit_1 
ON tblDIRGA_Item.Retail_Unit_ID = tblDIRGA_ItemUnit_1.Unit_ID)

在Teradata:

在Teradata中,我尝试使用两个不同的密钥(package_unit_id)和(retail_unit_id)从ir_item_unit_v表中选择unit_name两次。这在上面的Access中是如何工作的?

SELECT

    st.subteam_no
    ik.identifier
    **u.unit_name AS RetailUOM,**
    **uu.unit_name AS PackUOM**

FROM DRG_R.IR_PRICE_V ip

    JOIN ir_item_identifier_v ik
    ON ip.region = ik.region 
    AND ik.item_key = ip.item_key 

    JOIN ir_item_v i 
    ON ip.region = i.region
    AND i.item_key = ip.item_key 

    **JOIN ir_item_unit_v u AS ir_item_unit_1_v uu
    ON i.package_unit_id=u.unit_id
    AND i.region=u.region**

    **JOIN ir_item_unit_v u
    ON i.retail_unit_id=u.unit_id
    AND i.region=u.region**

2 个答案:

答案 0 :(得分:3)

它在Teradata中完全相同,分配不同的别名:

SELECT
   st.subteam_no
   ik.identifier,
   u.unit_name AS RetailUOM,
   uu.unit_name AS PackUOM
FROM DRG_R.IR_PRICE_V ip

JOIN ir_item_identifier_v AS ik
ON ip.region = ik.region 
AND ik.item_key = ip.item_key 

JOIN ir_item_v AS i 
ON ip.region = i.region
AND i.item_key = ip.item_key 

JOIN ir_item_unit_v AS u
ON i.package_unit_id=u.unit_id
AND i.region=u.region

JOIN ir_item_unit_v AS uu
ON i.retail_unit_id=uu.unit_id
AND i.region=uu.region

答案 1 :(得分:1)

您只需要为表提供两个不同的别名。也许u1和u2?只需确保在您的选择和加入中正确引用别名。