表table1,字段id,value
要选择id满足的条件是,同一个id对应的value值不唯一
比如table1:
id    value
1       90
1       60
2       90
2       90
这个id=1就是我想要的

解决方案 »

  1.   

    你是想根据ID查值??
      select value from tabl1 where id=1
      

  2.   

    --> 测试数据:#tb
    if object_id('tempdb.dbo.#tb') is not null drop table #tb
    create table #tb([id] int,[value] int)
    insert #tb
    select 1,90 union all
    select 1,60 union all
    select 2,90 union all
    select 2,90select [id],count(distinct [value]) from #tb
    group by id
    having count(distinct [value])>1
      

  3.   

    就是我要选择id值符合一定条件,不如在上例中id为1的两行,value值分别是90和60,而在id为2的两行,value值是90,我要的结果是:1
      

  4.   

    谢谢你的回答,那我不想选出value的个数count(distinct [value]) ,而是得到value的值呢
      

  5.   

    select [id] from #tb
    group by id
    having count(distinct [value])>1
      

  6.   

    if object_id('tempdb.dbo.#tb') is not null drop table #tb
    create table #tb([id] int,[value] int)
    insert #tb
    select 1,90 union all
    select 1,60 union all
    select 2,90 union all
    select 2,90select [id],count(distinct [value]) from #tb
    group by id
    having count(distinct [value])>1
    (所影响的行数为 4 行)id          value       
    ----------- ----------- 
    1           90
    1           60(所影响的行数为 2 行)
      

  7.   

    if object_id('tempdb.dbo.#tb') is not null drop table #tb
    create table #tb([id] int,[value] int)
    insert #tb
    select 1,90 union all
    select 1,60 union all
    select 2,90 union all
    select 2,90select * from #tb 
    where [id] in
    (select [id] from #tb
    group by id
    having count(distinct [value])>1)
    (所影响的行数为 4 行)id          value       
    ----------- ----------- 
    1           90
    1           60(所影响的行数为 2 行)