两个表 B 表的fd_person_id 与A表中的fd_id关联如下
A表
fd_id name
1 a
2 b
3 c
B表
fd_id fd_person_id
1 1
2 2现在要判断 给定一个 A表的 NAME 判断这个name 是否存在与A表中又不存在于B表中
比如 给name 为c 返回的count 为1 给a b d e 等都返回0
谢谢
A表
fd_id name
1 a
2 b
3 c
B表
fd_id fd_person_id
1 1
2 2现在要判断 给定一个 A表的 NAME 判断这个name 是否存在与A表中又不存在于B表中
比如 给name 为c 返回的count 为1 给a b d e 等都返回0
谢谢
SELECT COUNT(*)
FROM a
WHERE a.name = 'c' AND
NOT EXISTS (SELECT 1 FROM b WHERE b.fd_person_id = a.fd_id);
--使用not in
SELECT COUNT(*)
FROM a
WHERE a.name = 'c' AND
NOT a.fd_id IN (SELECT fd_person_id FROM b);
SELECT COUNT(*)
FROM a
WHERE a.name = 'c' AND
a.fd_id NOT IN (SELECT fd_person_id FROM b);
and b.fd_person_id is null
where name = '你的参数'
and a.fd_id in
(select fd_id from a
minus
select fd_id from b
);
where name = '你的参数'
and a.fd_id in
(select fd_id from a
minus
select fd_person_id fd_id from b
);
as
begin
select count(*) into v_num2 from A where name=d;
if v_num2<>0 then
dbms_output.put_line('此人在A中');
select count(*) into v_num from B where fd_person_id in(select fd_id from A where name=d);
if v_num=0 then
dbms_output.put_line('此人在A中,不在B中');
else
then
dbms_output.put_line('此人即在A中,也在B中');
end if;
else
dbms_output.put_line('此人不在A中');
end if;
end;