两个表 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
谢谢  

解决方案 »

  1.   

    --使用not exists 
    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);
      

  2.   

    --上面not in 写法有误,应该为
    SELECT COUNT(*)
      FROM a
     WHERE a.name = 'c' AND
           a.fd_id NOT  IN (SELECT fd_person_id FROM b);
      

  3.   

    select a.fd_id from A ,B where a.fd_id=b.fd_id(+) and name=''
    and b.fd_person_id is null
      

  4.   

    select count(fd_id) "count" from a 
    where name = '你的参数'
    and a.fd_id in
    (select fd_id from a
    minus
    select fd_id from b
    );
      

  5.   

    select count(fd_id) "count" from a 
    where name = '你的参数'
    and a.fd_id in
    (select fd_id from a
    minus
    select fd_person_id fd_id from b
    );
      

  6.   

    create or replace p(d varhcar2,v_num out number,v_num1 out number)
    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;
      

  7.   

    select count(*) from A as a where a.name='c' and a.fd_id not in (select fd_person_id from b)