【问题标题】:Joining on multiple tables in teradata加入 teradata 中的多个表
【发布时间】:2012-08-06 20:14:34
【问题描述】:

请帮我解决这个问题

sel a.col1,a.co2,a.col3,.........b.col1,b.col2..,c.col1,c.col2
from table1 as a inner join table2 as b on a.col1 =b.col1
inner join table3 as c on a.col1 = b.col1
where col1 = xxxxx;

现在我需要再加入一个表 table4。由于 table4 中没有 col1 作为主索引,因此我需要将其加入到另一个具有主键的表中。

以下是我需要将其包含在上述 sel 语句中的不同查询。

Sel xx.col1,yy.aaa,yy.bbb,zz.ccc,zz.ddd,zz.eee
from tablea as xx, tableb as yy, table4 as zz
where xx.col1 = yy.bbb and yy.aaa = zz.ccc

主索引:

  • table1、table2、table3、tablexx 的 col1
  • aaa 用于 tableb
  • 表4的ccc

提前致谢

【问题讨论】:

  • THIS IS IN TERADATA------------ 我的足迹:sel a.col1, a.co2, a.col3,.........b .col1,b.col2...,c.col1,c.col2,zz.ccc,z z.ddd,zz.eee from table4 as zz,table1 as a inner join table2 as b on a.col1 =b.col1内连接表 3 作为 a.col1 上的 c = b.col1 内连接表 b 作为 a.col1 上的 yy = yy.bbb 和 yy.aaa = zz.ccc 其中 col1 = xxxxx;错误:3782 连接表的搜索条件中的列引用不正确 谢谢
  • 在使表名和列名通用的过程中,您似乎引入了一些错误。因此,很难知道您是否遇到了问题,因为您的原始代码有语法错误,或者您是否在转换为通用名称时引入了它们。这是您的代码中明显错误的示例。您在第一个代码块中编写了“table 3 as c”。我假设您的意思是“table3 as c”。请使用示例表发布实际的 sql 或三次检查您翻译的 SQL 是否正确
  • @snoguy 。 . .可能是我在重新格式化查询时引入了一个杂散空间。

标签: sql database inner-join teradata


【解决方案1】:

怎么样:

Select a.leg,c.btn,p.prods,svc.sr,speed.test, a.leg, b.acct_id, e.emp_no, e.emp_name
FROM db1.tb1 as a 
    inner join db1.tb2 as C ON a.leg = C.leg 
    inner join db1.tb3 as p ON a.leg = p.leg 
    inner join db1.tb3 as svc on a.leg = svc.leg 
    inner join db2.tb4 as speed on a.leg = speed.leg
    inner join db4.tb1 as b on a.leg = b.sce_acct_id
    inner join db4.tb5 as e on b.acct_id = e.acct_id
where a.leg ='xxxx' 

【讨论】:

  • 选择 a.leg,c.btn,p.prods,svc.sr,speed.test FROM db1.tb1 作为 INNER JOIN db1.tb2 作为 C ON a.leg=C.leg INNER JOIN db1.tb3 as p ON a.leg=p.leg inner join db1.tb3 as svc on a.leg = svc.leg inner join db2.tb4 as speed on a.leg = speed.leg where leg ='xxxx'第二个查询 SELECT a.leg,b.acct_id,c.emp_no,c.emp_name FROM db1.tb1 a, db4.tb1 b, db4.tb5 c WHERE a.leg = b.sce_acct_id AND b.acct_id = c.acct_id Now如何将第二个查询加入第一个查询。
  • 我已根据您在评论中提供的信息提供了答案——但是请适当地使用该网站,以便找到此页面的其他人可以关注。具体来说,该信息是正确回答问题所必需的,因此它应该是问题的一部分,而不是对我的回答的评论。
  • @balaji - 请停止在评论中发布长代码。如果是答案,请发布答案。或者编辑您的问题并将其发布到那里。
  • @snowguy 因为我是这个网站的新手..我会确保遵守网站的条款。
猜你喜欢
  • 2017-08-03
  • 1970-01-01
  • 2018-08-16
  • 2012-09-25
  • 2016-10-06
  • 2020-10-02
  • 2017-02-01
  • 2018-04-29
相关资源
最近更新 更多