将INNER JOINS中的几个ON子句放在一起意味着什么

Ser*_*ero 5 t-sql sql-server sql-server-2005

我偶然发现了在SQL Server 2005数据库上创建的这个T-SQL查询:

Select s_bs.ScheduleHeaderId, 
       s_bs.ScheduleBatchScheduleId, 
       FlowRateOperational.FlowRate, 
       BatchScheduleFlowRateOperational.EffectiveStartTime, 
       BatchScheduleFlowRateOperational.EffectiveEndTime
From BatchSchedule as bs 
Inner Join ConnectionPoint as cp on bs.ConnectionPointId = cp.ConnectionPointId 
Inner Join ScheduleBatch as s_b 
Inner Join ScheduleConnectionPoint as s_cp 
Inner Join ScheduleBatchSchedule as s_bs 
            on s_cp.ScheduleConnectionPointId = s_bs.ScheduleConnectionPointId 
            on s_b.ScheduleBatchId = s_bs.ScheduleBatchId 
            on cp.ConnectionPointName = s_cp.ConnectionPointName and bs.BatchID = s_b.BatchID 
Inner Join BatchScheduleFlowRateOperational on bs.BatchScheduleId = BatchScheduleFlowRateOperational.BatchScheduleId 
Inner Join FlowRateOperational on BatchScheduleFlowRateOperational.FlowRateOperationalId = FlowRateOperational.FlowRateOperationalId
Run Code Online (Sandbox Code Playgroud)

到目前为止我不是SQL专家,但至少我认为我知道如何连接表,我以前从未见过这种连接表的方式.

在他们的JOINS产生不同的结果或提高性能后,有几个ON条款?

为什么这个人只能移动连接并将ON子句保持在相应的JOIN旁边?

感谢你能解开这个"神秘"的任何光明:)

Sin*_*ian 1

ON子句可以放在每个后面INNER JOIN(这对我来说看起来更好)。但有时不可避免地将ON前几个连接的子句放在后面的连接之后。例如提供连接条件的表在链中尚不可用JOIN,例如:

SELECT * FROM 
A INNER JOIN 
B INNER JOIN 
C 
   ON B.Col1 = C.Col1 
   ON A.Col2 = C.Col2
Run Code Online (Sandbox Code Playgroud)

看看这两个ON子句都引用了C,因此相关ON子句不能更早出现。可以通过放在第一位来防止这种情况C,但根据用法,人们可能会发现它的可读性较差。

上面只是从语法的角度来看。还应该有一些性能方面的考虑,但我不知道。