0

我在 SQL 查询上苦苦挣扎......我有三个表:

1) 职位

2) 纸1

3) 纸2

paper1paper2有一个列job_id,其中引用了相应的作业 ID;因此 id为123的作业的apaper1.job_id123

现在我想查看所有有相应paper1但没有的工作paper2(因此:未完成,因为paper1paper2是要完成的工作的要求)。我的尝试是这样的,但结果不正确:

SELECT id 
FROM   jobs 
WHERE  (SELECT id FROM paper1 WHERE (job_id = jobs.id) != 0 LIMIT 1) 
AND    (SELECT id FROM paper2 WHERE (job_id = jobs.id)  = NULL LIMIT 1)

任何帮助表示赞赏;谢谢。

4

3 回答 3

1
select id 
from jobs 
where exists (select p1.id from paper1 as p1 where p1.job_id = jobs.id)
    and not exists (select p2.id from paper2 as p2 where p2.job_id = jobs.id)
于 2013-03-04T12:34:17.273 回答
0

根据我的理解,我认为您只需要仅在 paper1 中而不在 paper2 中的工作,如果这是要求,请尝试以下代码

select * from jobs where id in (select distinct j1 from 
(select a.job_id as j1,b.job_id as j2 from paper1 a,paper2 b where a.job_id=b.job_id(+)) 
where j2 is null)
于 2013-03-04T12:35:24.963 回答
0

尝试:

Select job_id 
FROM paper1 
WHERE job_id NOT IN (Select job_id from paper2 group by paper2)

GROUP BY job_id;
于 2013-03-05T07:56:04.130 回答