SQL:我怎么读这个?

时间:2014-01-28 13:32:07

标签: sql-server join

我有这条SQL指令(由其他人提供)

FROM P INNER JOIN
C ON P.p1 = C.p1 INNER JOIN
G INNER JOIN
U ON G.u1 = U.u1 ON
C.c1 = G.c1 INNER JOIN
R ON P.r1 = R.r1 INNER JOIN
F ON U.f1 = F.f1 RIGHT OUTER JOIN
UN ON U.u1 = UN.u1

我怎么读这一切?第2,第3,第4和第5行如何工作?

1 个答案:

答案 0 :(得分:3)

通过一些格式化,我认为它变得更容易:

FROM P INNER JOIN C 
   ON P.p1 = C.p1 
INNER JOIN G 
INNER JOIN U 
   ON G.u1 = U.u1 
   ON C.c1 = G.c1 
INNER JOIN R 
   ON P.r1 = R.r1 
INNER JOIN F 
   ON U.f1 = F.f1 
RIGHT OUTER JOIN UN 
    ON U.u1 = UN.u1

然后看起来你的一个人在错误的地方:

FROM P INNER JOIN C 
   ON P.p1 = C.p1 
INNER JOIN G 
   **ON C.c1 = G.c1**       
INNER JOIN U        
    ON G.u1 = U.u1
INNER JOIN R 
   ON P.r1 = R.r1 
INNER JOIN F 
   ON U.f1 = F.f1 
RIGHT OUTER JOIN UN 
    ON U.u1 = UN.u1

格式化真的有助于这种事情......