在oracle中连接三个表或执行嵌套的sql语句

pet*_*tey 3 sql database oracle select join

连接三个表或在oracle中执行嵌套的sql

我有三张桌子:gut,pos和cfg

肠和pos共享一个值,可以使用连接 gut.gut_val= pos.pos_val.

类似地,cfg和pos表共享一个值,并且可以使用以下内容进行连接:cfg.cfg_dev_cot = pos.pos_dev_val.

然而,cfg和gut不会共享一个值.我想要做的是显示gut_cou,pos_mon_runch和cfg_cfg_cou的值,当 gut_val = pos_val和时cfg_dev_cot = pos_dev_val.有没有办法用连接执行此操作,还是最好是执行嵌套的sql语句?

我试过的是以下但它抛出了一个oracle错误.

select gut.gut_cou, pos.pos_mon_runch, cfg.cfg_cou
from gut,pos,cfg
where gut.gut_val = pos.pos_val
and cfg.cfg_dev_cot = pos.pos_dev_val
and pos.POS_CIT='12345654'
and gut.gut_DAT_DEB <= '08-AUG-11'
and gut.gut_DAT_FIN >= '08-AUG-11'
and gut.gut_TCV ='BOU' 
Run Code Online (Sandbox Code Playgroud)

Mat*_*lie 5

首先,摆脱谁曾经或曾经教过你使用,符号加入的人.相反,使用类似下面的内容.

这可能无法消除您的错误消息,但您没有告诉我们错误是什么;)

SELECT
  gut.gut_cou,
  pos.pos_mon_ruch,
  cfg.cfg_cou
FROM
  gut
INNER JOIN
  pos
    ON pos.pos_val = gut.gut_val
INNER JOIN
  cfg
    ON cfg.cfg_dev_cot = pos.pos_dev_val
WHERE
    pos.POS_CIT='12345654'
AND gut.gut_DAT_DEB <= '08-AUG-11'
AND gut.gut_DAT_FIN >= '08-AUG-11'
AND gut.gut_TCV ='BOU'
Run Code Online (Sandbox Code Playgroud)