暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

Mysql查询not in为什么返回空结果

云自由 2022-12-06
783

在Mysql查询语句中,使用了not int,原本应该返回结果的数据,却返回了空值。

原因是:

not in中不能包含null值,如果包含null值,则不会返回数据,直接返回空结果集。

解决:

在后面加一个非空判断就可以避免null值

示例:


select name from table1 where name not in (
 select name from table2 where name is not null
);

 SELECT b.* from
(
SELECT min(序号)序号,身份证号 from  `202211代缴2023原始数据`
where
(year(now())-year(substring(身份证号,7,8))>=16
and
year(now())-year(substring(身份证号,7,8))<=59
) and 身份证号 not in
(SELECT sfzh from `202211领取待遇人员` where sfzh is not null)
and 身份证号 not in
(SELECT sfzh from `202211在校学生` where sfzh is not null)
GROUP BY `身份证号`
)a  
left join `202211代缴2023原始数据` b on a.序号=b.序号



文章转载自云自由,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论