--查询有权限的人员
select distinct a.names,a.bh,b.deptName,c.flags,c.ms
from consumes a,dept b,y_mj_qx1 c,y_mj_doors d
where a.bh=c.badge and c.doorid=d.doorid and a.deptcode=b.deptcode
这条SQL语句我查出来15个人--查询所有的人员
select distinct a.names,a.bh,b.deptName,c.flags,c.ms
from consumes a,dept b,y_mj_qx1 c,y_mj_doors d
where  c.doorid=d.doorid and a.deptcode=b.deptcode
这个SQL语句我查出来7个人--查询没有权限的人员
按道理这里应该要出来8个人。可是我怎么写都不对。很纠结。
这  该怎么写呢。
     求解。
在线等。正解马上给分。

解决方案 »

  1.   


    不在有权限的人员中的人都是没有权限的吧。意思就是说除掉有权限的人,剩余的人都是没有权限的吧。你可以用not in,例如select * from a where name not in(里面可以加你查询出来的东西,但是返回值必须是相同的字段name)。 
      

  2.   

    你的描述我难理解,,而且,你发的这sql语句,表名都不描述下,,谁知道如何改???
      

  3.   

    select distinct a.names,a.bh,b.deptName,c.flags,c.ms
    from consumes a,dept b,y_mj_qx1 c,y_mj_doors d
    where c.doorid=d.doorid and a.deptcode=b.deptcode 
    and not (a.bh=c.badge)
    --或
    select distinct a.names,a.bh,b.deptName,c.flags,c.ms
    from consumes a,dept b,y_mj_qx1 c,y_mj_doors d
    where c.doorid=d.doorid and a.deptcode=b.deptcode 
    and  a.bh!=c.badge
      

  4.   

    select
     distinct a.names,a.bh,b.deptName,c.flags,c.ms
    from
     consumes a,dept b,y_mj_qx1 c,y_mj_doors d
    where
     c.doorid=d.doorid and a.deptcode=b.deptcode 
    and
     a.bh<>c.badge