select id from ta group by id having count(*)>1

解决方案 »

  1.   

    ---测试数据---
    if object_id('[A]') is not null drop table [A]
    go
    create table [A]([id] int,[name] varchar(2))
    insert [A]
    select 1,'tt' union all
    select 2,'rr' union all
    select 2,'gg' union all
    select 3,'er' union all
    select 4,'dd' union all
    select 3,'bb' union all
    select 3,'ww'
     
    ---查询---
    select distinct id from [A] t where (select count(1) from A where id=t.id)>=2
    ---结果---
    id          
    ----------- 
    2
    3(所影响的行数为 2 行)