比如数据有
intID intUserNum
1     10
1     11
2     10
2     10 
3     12
3     12
3     12
4     13
4     13
4     14请问怎么用select查找出intID为
1
4
的记录,条件是后面的intUserNum不同.

解决方案 »

  1.   

    select distinct * from tablename where intID in (1,4)
      

  2.   

    create table #temp
    (intID int,
    intUserNum int)
    insert into #temp
    select '1','10' union all select '1','11' union all select '2','10' union all select '2','10' union all select '3','12' union all select '3','12' union all select '3','12' union all select '4','13' union all select '4','13' union all select '4','14'
    select * from #temp
    select distinct intID from #temp a 
    where (select count(distinct intUserNum) from #temp where intID=a.intID)>1------------
    1
    4
      

  3.   

    select id from tb
    group by id
    having count(distinct intUserNum)>1
      

  4.   

    噢,对,
    用wangdehao(找找找(现在很幸福)) 的简单多了
      

  5.   

    create table #temp
    (intID int,
    intUserNum int)
    insert into #temp
    select '1','10' union all select '1','11' union all select '2','10' union all select '2','10' union all select '3','12' union all select '3','12' union all select '3','12' union all select '4','13' union all select '4','13' union all select '4','14'
    select intid from #temp group by intid having count(distinct intusernum)>1drop table #temp
      

  6.   

    没彻底明白意思  是重复得留一条?
    select distinct * from where intID=1 or intID=4