我尝试了很多这个陈述,但我无法得到我想要的结果
这是合作表:
每个合作者都应该知道其他合作者,他们有collaborator_complete = 1,与他在同一个任务中。还有Joint_State ='接受'
例如:
表示collabortor_ID = 14 应该知道1,2,11和12谁有collaborator_complete = 1并与14共享任务48。
我试试这句话
它将从任务中选择协作者,其中14不在此任务中 比如image2中的前两行结果
答案 0 :(得分:1)
您需要查看其他行。这表示join
或in
或exists
:
select ct.*
from collaborative_task ct
where collaborator_complete = 1 and join_state = 'Accept' and
collaborator_id <> 14 and
exists (select 1
from collaborative_task ct2
where ct2.task_id = ct.task_id and
ct2.collaborator_id = 14
);
答案 1 :(得分:1)
您可以执行JOIN
:
SELECT
t2.Collaborator_ID
FROM collaborative_task t1
INNER JOIN collaborative_task t2
ON t2.task_ID = t1.task_id
AND t2.collaborator_ID <> t1.collaborator_ID
WHERE
t1.collaborator_id = 14
AND t2.collaborator_complete = 1
AND t2.Join_State = 'Accept'