【发布时间】:2014-03-10 07:42:36
【问题描述】:
我正在尝试理解 SQL。我按照下面的逻辑是正确的吗?我可以像这里一样使用括号吗?
-- 1
(table1) inner join (table2) on ( ??? )
-- 2
(table1 as a) inner join (table2 as b) on (a.col1 = b.col1)
-- 3
((select ... from ... where ...) as a)
inner join
((select ... from ... where ...) as b)
on (a.col1 = b.col1)
这对我不起作用。
我失败的查询:
((select CREATEDATE, BELEGNRRECH, MNR, UTNR, KTXT
from INFOR.RELFBR
where (SAINT = '90') and (CREATEDATE >= '01.01.14 00:00:00')) as a)
inner join
((select ANR, MNR from INFOR.RELXDB where (SAINT = '10')) as b)
on (a.MNR = b.MNR)
-- error message: ORA-00907: missing right parenthesis
我正在使用 C# 发送 SQL 查询:
string q1 = "select CREATEDATE, BELEGNRRECH, MNR, UTNR, KTXT from INFOR.RELFBR " +
"where (SAINT = '90') and (CREATEDATE >= '" + date.ToString("dd.MM.yy HH:mm:ss") + "')";
string q2 = "select ANR, MNR from INFOR.RELXDB where (SAINT = '10')";
string query = "(" + q1 + ") as a inner join (" + q2 + ") as b on (a.MNR = b.MNR)";
// q1 and q2 work, not query
【问题讨论】:
标签: sql join syntax inner-join