[英]Joining 3 tables in sql oracle
我知道这很简单,但是我是sql新手,也不知道如何编写此查询。 我有3张桌子:rekon,流程和注释。
rekon:
no sex
a F
b F
c M
d F
e M
流:
no notes_no
a PX
a SX
a
a DX
b MX
b CX
c
c PX
d LX
d WX
笔记:
notes_no no
AX a
BX f
CX g
DX a
EX c
FX c
GX g
HX b
PX a
SX a
我要列出注释中的所有条目,这些注释不是流程的一部分,仅适用于rekon的女性客户。 所以结果应该是
no sex notes_no
a F AX
b F HX
我尝试使用语句
notes.notes_no not in (select distinct notes_no from flows)
但是我必须有很多行,并且oracle在计算它时遇到了问题。
先感谢您。
select N.*
from rekon R
join notes N
on N.no = R.no
where R.sex = 'F'
and not exists (
select 1
from flows F
where F.notes_no = N.notes_no
)
;
根据表间引用关系的定义,查询可能会略有不同,因此exists
谓词也可能会被读取
and not exists (
select 1
from flows F
where F.no = N.no
and F.notes_no = N.notes_no
)
如果您的Oracle在合理时间内查询数据有问题,那么您可能会
试试这个查询:
SELECT notes.* FROM notes
INNER JOIN rekon ON rekon.no = notes.no
LEFT JOIN flows ON flows.no = notes.no
WHERE flows.no IS NULL and sex = 'F'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.