gpt4 book ai didi

Mysql not in 语句不工作

转载 作者:行者123 更新时间:2023-11-29 08:23:08 24 4
gpt4 key购买 nike

简化问题:

如果我有以下内容(其中 CN = 姓名,UID = 员工 ID,主管 = 主管的员工 ID):

CN          UID      supervisor  
Jerry 4 NULL
Dave 11 15
Dan 12 16
Jack 13 17
Jason 14 11
Tom 10 15
Berry 16 12

我预计 Dave 或 Dan 都不在名单上,因为他们也是主管(第二位或更高级别)。

    SELECT
reports_accreditallfr.cn,
reports_accreditallfr.uid,
reports_accreditallfr.supervisor
FROM
reports_accreditallfr
WHERE
reports_accreditallfr.uid NOT IN ( reports_accreditallfr.supervisor)

我现在的陈述已经说明了一切。我猜我的 NOT IN 语句只是逐行工作,而不是扫描整个主管列。

最佳答案

您需要一个子查询。

SELECT reports_accreditallfr.cn, reports_accreditallfr.uid,
reports_accreditallfr.supervisor
FROM reports_accreditallfr
WHERE reports_accreditallfr.uid NOT IN (select reports_accreditallfr.supervisor
from reports_accreditallfr
where reports_accreditallfr.supervisor is not null
);

您的表达式相当于:

reports_accreditallfr.uid <> reports_accreditallfr.supervisor

这可能对所有行都是如此。

关于Mysql not in 语句不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18750598/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com