这是什么规律?只是对MID排序吗,也不像阿!

解决方案 »

  1.   

    就是Machine表中的CID与Card中的CID比较,把MID没有CID的列再来
      

  2.   

    select * from machine
    union 
    select * from Card
      

  3.   

    select * from (select * from machine
    union all
    select * from Card)T order by T.cid
      

  4.   

    包含 UNION 运算符的查询表达式中的所有查询都必须在选择列表中包含同样数目的表达式。
      

  5.   

    select distinct m.mid, c.cid from m, c where convert(char(10), m.mid) + convert(char(10), c.cid) not in (select convert(char(10), m.mid) + convert(char(10), m.cid) from m)/*结果
    mid        cid        
    ---------- ---------- 
    01         111       
    01         222       
    01         333       
    01         789       
    02         111       
    02         222       
    02         456       
    02         789       (所影响的行数为 8 行)
    */
      

  6.   

    select * from m
    select * from cselect distinct m.mid, c.cid from m, c where convert(char(10), m.mid) + convert(char(10), c.cid) not in (select convert(char(10), m.mid) + convert(char(10), m.cid) from m)/*
    mid        cid        
    ---------- ---------- 
    01         123       
    02         123       
    01         456       
    02         333       (所影响的行数为 4 行)cid        
    ---------- 
    123       
    456       
    789       
    111       
    222       
    333       (所影响的行数为 6 行)mid        cid        
    ---------- ---------- 
    01         111       
    01         222       
    01         333       
    01         789       
    02         111       
    02         222       
    02         456       
    02         789       (所影响的行数为 8 行)
    */
      

  7.   

    ---测试数据
    CREATE TABLE #Machine(MID char(10),CID char(10))
    CREATE TABLE #Card(CID char(10))insert into #Machine
    select '01','123'
    union all
    select '02','123'
    union all
    select '01','456'
    union all
    select '02','333'
    insert #Card
    select '123'
    union all
    select '456'
    union all
    select '789'
    union all
    select '111'
    union all
    select '222'
    union all
    select '333'--执行语句
    select a.mid,b.cid from (select distinct mid from #Machine) a inner join #card b on 1=1 where b.cid not in (select cid from #Machine where mid =a.mid)
    order by a.mid
      

  8.   

    to 楼主:Mryu666 的结果是6行,我的是8行,到底哪个对?辛苦帮你写了1个小时,就给我20分?如果我的答案不对的话,不给我分也行我现在认为你把80分给一个错误的答案了