0

我有以下四个具有以下结构的表

表 A

  ColA1  ColA2  ColA3    ColA4  ColA5
-----------------------------------------
  AA     100      CC     DD       EE

表 B

  ColB1  ColB2  ColB3    ColB4   ColB5
 -------------------------------------------
 AA      100     40452   A9       CDE

当它们two tables像下面这样加入时:

 Select colA1,ColA2, ColA3, ColA4, ColB3,ColB4, ColB5
   from table A
        Left outer join 
            (select ColB3, ColB4, ColB5
              from table B
              where colB3 = (select max(colB3) from table B
            )
          on (colA1 = colB1 and ColA2 = col B2);

现在我必须加入下table C一个table B

表C结构是

 ColD1   ColD2   ColD3
 --------------------------------  
  Desc1 A9   Executive
  Desc1 A7   Engineer

我有共同的专栏,比如ColD2 and colB4得到Col D3

我如何加入existing query + join between表b和表c?

4

1 回答 1

0

未经测试,但它会像下面给出的

 SELECT colA1,ColA2, ColA3, ColA4, ColB3,ColB4, ColB5,ColD3
   FROM table A
        LEFT OUTER JOIN 
            (SELECT ColB3, ColB4, ColB5
              FROM table B
              WHERE colB3 = (SELECT MAX(colB3) FROM table B
            )
          ON (colA1 = colB1 AND ColA2 = col B2)
        LEFT OUTER JOIN TABLE C
          ON (colB4=colD2);
于 2012-06-20T04:20:02.670 回答