各位高手怎么写!谢谢 
1.im_member表中的bs_uid字段对应的是  tbl_CompanyUser表中的Id字段
2.tbl_CompanyUser表中的ContactMQ字段对应的是im_member表中的im_uid字段
3.tbl_CompanyInfo表中的ContactMQ字段对应的是tbl_CompanyUser表中isadmin=1情况下tbl_CompanyUser表中的ContactMQ字段
tbl_CompanyInfo与tbl_CompanyUser的主外键关系为tbl_CompanyInfo.Id=tbl_CompanyUser.CompanyId现要求查询:
1.tbl_CompanyUser表中ContactMQ字段与im_member表中的im_uid字段值没有一一对应的记录
2.tbl_CompanyInfo表中的ContactMQ字段没有与tbl_CompanyUser表中isadmin=1情况下tbl_CompanyUser表中的ContactMQ字段一一对应的记录这样是不是错了?
select t.*,a.* from tbl_CompanyUser as t inner join im_member as a  on  a.bs_uid<>t.ContactMQ

解决方案 »

  1.   

    1.im_member表中的bs_uid字段对应的是  tbl_CompanyUser表中的Id字段
    2.tbl_CompanyUser表中的ContactMQ字段对应的是im_member表中的im_uid字段
    3.tbl_CompanyInfo表中的ContactMQ字段对应的是tbl_CompanyUser表中isadmin=1情况下tbl_CompanyUser表中的ContactMQ字段
    tbl_CompanyInfo与tbl_CompanyUser的主外键关系为tbl_CompanyInfo.Id=tbl_CompanyUser.CompanyId现要求查询:
    1.tbl_CompanyUser表中ContactMQ字段与im_member表中的im_uid字段值没有一一对应的记录
    2.tbl_CompanyInfo表中的ContactMQ字段没有与tbl_CompanyUser表中isadmin=1情况下tbl_CompanyUser表中的ContactMQ字段一一对应的记录
      

  2.   

    第一个问题,要用not in 或 not exists
    select * from tbl_CompanyUser where ContactMQ not in(select im_uid from im_member)
    第二个问题,类似
      

  3.   

    1.tbl_CompanyUser表中ContactMQ字段与im_member表中的im_uid字段值没有一一对应的记录select ContactMQ from tbl_CompanyUser where ContactMQ not in (select im_uid from im_member)select ContactMQ from tbl_CompanyUser where ContactMQ not in (select im_uid from im_member)
    union all
    select ContactMQ from tbl_CompanyUser group by ContactMQ having count(1) > 12.tbl_CompanyInfo表中的ContactMQ字段没有与tbl_CompanyUser表中isadmin=1情况下tbl_CompanyUser表中的ContactMQ字段一一对应的记录select ContactMQ from tbl_CompanyInfo where ContactMQ not in (select ContactMQ from tbl_CompanyUser where isadmin=1)select ContactMQ from tbl_CompanyInfo where ContactMQ not in (select ContactMQ from tbl_CompanyUser where isadmin=1)
    union all
    select ContactMQ from tbl_CompanyInfo group by ContactMQ having count(1) > 1
      

  4.   

    select ContactMQ from tbl_CompanyUser where ContactMQ not in (select im_uid from im_member)
    union all
    select ContactMQ from tbl_CompanyUser group by ContactMQ having count(1) > 1
    这个查出来为null 
    第一个可以