SQL2000,一个表[合同表]
有2列,合同号,客户,我想筛选出 同一个合同号,有不同的客户,把数据select出来[合同号]      [客户]
12           客户1
12           客户2
34           客户3
35           客户3
数据结果应该是
12        客户1
12        客户2

解决方案 »

  1.   

    select 合同号,客户 from tb a 
    where  exists(select 1 from tb where a.id=id )
      

  2.   

    select 合同号,客户 from tb a 
    where  exists(select 1 from tb where a.合同号=合同号 )
      

  3.   


    select 合同号,count(distinct 客户) count into #temp
    from 表
    group by 合同号
    having count(distinct 客户)>1
    select * from 表 where 合同号 in (select 合同号 from #temp);
      

  4.   

    CREATE TABLE #temp
    (
    [合同号] NVARCHAR(10),
    [客户] NVARCHAR(10)
    )
    INSERT #temp
    select '12', N'客户1' union all
    select '12', N'客户2' union all
    select '34', N'客户3' union all
    select '35', N'客户3'
    go
    SELECT DISTINCT
    [合同号],
    [客户]
    FROM #temp T
    WHERE EXISTS(SELECT 1 FROM #temp WHERE 合同号 = T.合同号 AND 客户 <> T.客户)
    /*
    合同号        客户
    ---------- ----------
    12         客户1
    12         客户2
    */