表Top_Cust,主键typ,custid
表Top_User_QX,主键typ,custid
得到Top_Cust中typ,custid 不包含在Top_User_QX里的记录快速结贴

解决方案 »

  1.   

    SELECT typ,custid  FROM Top_Cust WHERE typ NOT IN (SELECT typ FROM Top_User_QX) AND custid  NOT IN (SELECT custid    FROM Top_User_QX)
      

  2.   

    复合主键?select typ,custid from Top_cust except (select typ,custid from top_user_qx)
      

  3.   

    这样不行吧
    我的意思是主键的组合不在那里面
    不是单个
    比如
    A数据
    typ       custid
    客户        001
    客户        002
    客户        003
    供应商      001
    供应商      002
    供应商      003
    B数据
    typ       custid
    客户        002
    供应商      001那么出来的应该是
    typ       custid
    客户        001
    客户        003
    供应商      002
    供应商      003
     
      

  4.   

    回2搂select typ,custid from Top_Cust except (select custtype 'typ',custid from Top_User_QX_Cust where uid='李林华')服务器: 消息 156,级别 15,状态 1,行 1
    在关键字 'except' 附近有语法错误。
      

  5.   

    custtype是什么?except sql server是受支持的啊,我用过
      

  6.   

    好像不支持的,我是sql2000
    custtype列名,其实就是和typ对应的
      

  7.   

    SELECT   typ,custid     FROM   Top_Cust   WHERE   typ   NOT   IN   (SELECT   typ   FROM   Top_User_QX)   AND   custid     NOT   IN   (SELECT   custid         FROM   Top_User_QX) 
    ----------------------------------------------------------------------------------------
    一楼的应该就能满足呀!!
      

  8.   

    一楼的绝对不行
    我都测试过了
    如果数据如下,客户 001不会出来,但是应该出来的
    A数据 
    typ               custid 
    客户                 001 
    客户                 002 
    客户                 003 
    供应商             001 
    供应商             002 
    供应商             003 
    B数据 
    typ               custid 
    客户                 002 
    供应商             001 那么出来的应该是 
    typ               custid 
    客户                 001 
    客户                 003 
    供应商             002 
    供应商             003 
      

  9.   

    自己解决了
    select a.typ,a.custid from Top_Cust a 
    left outer join Top_User_QX_Cust b
    on a.custid=b.custid and a.typ=b.custtype and b.uid='李林华'
    where b.uid is null
    本来看去except挺好的
      

  10.   


    select   typ,custid   from   Top_Cust   except   (select custtype as typ,custid   from   Top_User_QX_Cust   where   uid='李林华') 这样看看
      

  11.   

    不灭的传说,你好,不行的 
    其实 as typ 和'typ' 都一样
    估计不支持except
      

  12.   

    select typ,custid from top_user where not exists (select typ,custid from top_user_qx where top_user_qx.typ=top_user.typ and top_user_qx.custid=top_user)