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

    select * from a where not exists (select 1 from b where a.fd_id=b.fd_id)and a.name='c'
      

  2.   

    select count(1) as cnt from b where exists(select 1 from a where a.fd_id= b.fd_person_id and name='c')
      

  3.   

    select name,num=count(*)
    from A left join B on A.fd_id=B.fd_person_id
    where B.fd_id is null and name='c'
    group by name