简体   繁体   English

如何在 Big Query 中编写多个连接

[英]how to write more than one joins in Big Query

I want to convert following Oracle query into equivalent Big Query SQL.我想将以下 Oracle 查询转换为等效的大查询 SQL。

Below is old syntax of right join but same operator (+) is not available in Big Query.以下是右连接的旧语法,但 same operator (+) 在 Big Query 中不可用。


SELECT * FROM 
t1,t2,t3,t4,t5,t6,t7,t8,t9,t10
WHERE 
    t1.CODE (+) = t2.CODE
AND t1.BRANCH_NBR (+) = t2.BRANCH_NBR
AND t1.NBR (+) = t2.NBR
AND t1.DT (+) = t2.DT

AND t3.COMPANY (+) = t4.CODE
AND t3.INV_PART_NBR (+) = t4.PART_NBR
AND t5.COMPANY (+) = t3.COMPANY
AND t5.CLIENT_NBR (+) = t3.CLIENT_NBR
AND t5.SEQ_NBR (+) = t3.SEQ_NBR
AND t6.COMPANY (+) = t3.COMPANY
AND t6.CLIENT_NBR (+) = t3.CLIENT_NBR
AND t6.SEQ_NBR (+) = t3.SEQ_NBR

AND t7.COMPANY (+) = t8.COMPANY
AND t7.CLIENT_NBR (+) = t8.MV_NUMBER
AND t7.VENDOR_CLASS (+) = 'A'
AND t9.COMPANY (+) = t2.CODE
AND t9.BR_NBR (+) = t2.BB_NBR
AND t9.CUST_NBR (+) = t2.BC_NBR
AND t9.SUFFIX (+) = t2.SHIP_TO_SFX
AND t10.COMPANY (+) = t2.CODE
AND t10.BR_NBR (+) = t2.BB_NBR
AND t10.CUST_NBR (+) = t2.BC_NBR
AND t10.SUFFIX (+) = '000'

I tried with right outer join but received errors.我尝试使用右外连接但收到错误。 this is sample join statements from actual code and not pasting all join这是来自实际代码的示例连接语句,而不是粘贴所有连接

SELECT *
FROM
`t1` AS t1
RIGHT OUTER JOIN `t2` AS t2 USING (CODE,BRANCH_NBR,NMBR,DT),
`t3` AS t3
RIGHT OUTER JOIN 't4' AS t4 USING (CODE,PART_NBR,COMPANY)

Error received Syntax error: RIGHT JOIN must be parenthesized when following a comma join.收到错误语法错误:在逗号连接之后必须用括号括起 RIGHT JOIN。 Also, if the preceding comma join is a correlated CROSS JOIN that unnests an array, then CROSS JOIN syntax must be used in place of the comma join此外,如果前面的逗号连接是取消嵌套数组的相关 CROSS JOIN,则必须使用 CROSS JOIN 语法代替逗号连接

(+) operator in oracle is an operator used for performing joins. oracle 中的 (+) 运算符是用于执行连接的运算符。

SELECT * FROM t1,t2 WHERE t1.CODE (+) = t2.CODE SELECT * 从 t1,t2 到 t1.CODE (+) = t2.CODE

Now, an equivalent would be现在,相当于

SELECT * FROM t2 left join t1 on t1.CODE = t2.CODE SELECT * FROM t2 left join t1 on t1.CODE = t2.CODE

Similarly, it will apply for all tables and once changed, your result should appear as expected.同样,它将应用于所有表,一旦更改,您的结果应该会按预期显示。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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