select
    b.softwareName,c.computer_id
from
    (select distinct softwareName from A) b,
    (select distinct computer_id  from A) c
where
    not exists(select 1 from A where softwareName=b.softwareName and computer_id=c.computer_id)
    and
    b.softwareName in('软件1','软件3')

解决方案 »

  1.   

    --创建测试数据
    create table A(computer_id varchar(20),softwareName varchar(20))
    insert into A select '电脑1','软件1'
    insert into A select '电脑1','软件2'
    insert into A select '电脑2','软件1'
    insert into A select '电脑2','软件3'
    insert into A select '电脑3','软件4'
    --执行查询
    select
        b.softwareName,c.computer_id
    from
        (select distinct softwareName from A) b,
        (select distinct computer_id  from A) c
    where
        not exists(select 1 from A where softwareName=b.softwareName and computer_id=c.computer_id)
        and
        b.softwareName in('软件1','软件3')--输出结果
    /*
    softwareName  computer_id
    ------------  -----------
    软件1         电脑3
    软件3         电脑1
    软件3         电脑3
    */--删除测试数据
    drop table A
      

  2.   

    select t1.computer_id
           ,t2.softwareName
    from (select distinct computer_id from A) t1
    join (select distinct softwareName from A)t2 on 1>0
    left join A on t1.computer_id=A.computer_id
                   and t2.softwareName=A.softwareName
    where A.softwareName is null
          and
          t2.softwareName in ('软件1','软件3')
      

  3.   

    --测试数据
    declare @a table(computer_id varchar(20),softwareName varchar(20))
    insert into @a
    select '电脑1','软件1' union all
    select '电脑1','软件2' union all
    select '电脑2','软件1' union all
    select '电脑2','软件3' union all
    select '电脑3','软件4'--处理
    select * 
    from (select * 
    from (select distinct computer_id from @a) a,
         (select '软件1' as softwarename union all select '软件3') b
         ) new
    where not exists(select 1 from @a where computer_id=new.computer_id and softwarename=new.softwarename)/*
    结果
    ------------------------------
    电脑1 软件3
    电脑3 软件1
    电脑3 软件3
    */
      

  4.   

    select softwareName,computer_id from a where softwareName  !='软件1' and softwareName  !='软件3'
      

  5.   

    select * from A where softwareName not in ('软件1','软件3')
      

  6.   

    不好意思上面没有正确领会楼主的意思!select * from
    (
    select tpA.computerId,tpB.softwarename 
    from 
    (select distinct computerId from a) tpA,
    (select '软件1' as softwarename 
     union all
     select '软件2' as softwarename ) tpB
    ) Tp
    where not exist ... 不想写了..