现在遇到一个问题,始终不知道如何解决。
要写的SQL语句的功能是取出某几张表中的数据不含指定表中的某几行的数据;
首先我的取出整体的记录SQL语句如下:
查询结果集如下:
查询该集中的部分集SQL代码如下:
执行结果如下:planMaker
为何我在两段SQL语句中间加NOT EXISTS语句时,就无法查询获得结果?
合起来的SQL语句如下:
not EXISTS 通俗点讲,就是返回一个boolean类型 。也就是你的这个条件的意思,如果
SELECT
militarySuperviseQuarterSubmissionTable.fileSubmissionPersonId
FROM
militarySuperviseQuarterSubmissionTable,
projectMemberRelationTable
WHERE
militarySuperviseQuarterSubmissionTable.fileSubmissionPersonId = projectMemberRelationTable.systemUserID
AND projectMemberRelationTable.projectID = 22
AND militarySuperviseQuarterSubmissionTable.militarySuperVisorUniqueId = 2
这里有查询出来没有数据,条件才成立
废话不多说,你想要的结果应该是这样的吧:
SELECT
BSPMSuser.userName,
BSPMSuser.userDepartment,
projectMemberRelationTable.systemUserID,
userAuthority.authorityName,
BSPMSuser.MemberResponsiblity,
BSPMSuser.memberPosition,
BSPMSuser.MemberTitle,
BSPMSuser.memberAddress,
BSPMSuser.userPhoneNumber,
BSPMSuser.memberNote
FROM
BSPMSuser,
userAuthority,
militarySuperviseQuarterSubmissionTable,
projectMemberRelationTable
WHERE
projectMemberRelationTable.projectID = 22
AND projectMemberRelationTable.authorityId = userAuthority.userGroupID
AND projectMemberRelationTable.systemUserID = BSPMSuser.userID
AND NOT IN (
SELECT
militarySuperviseQuarterSubmissionTable.fileSubmissionPersonId
FROM
militarySuperviseQuarterSubmissionTable,
projectMemberRelationTable
WHERE
militarySuperviseQuarterSubmissionTable.fileSubmissionPersonId = projectMemberRelationTable.systemUserID
AND projectMemberRelationTable.projectID = 22
AND militarySuperviseQuarterSubmissionTable.militarySuperVisorUniqueId = 2
);
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。