select a.* from guest a where exists(select 1 from guest where Age=a.Age and ID!=A.ID)

解决方案 »

  1.   

    create table Guest(
    id int identity,
    Age int,
    Tel int
    )
    insert into Guest values(20,null)
    insert into Guest values(30,null)
    insert into Guest values(20,null)
    insert into Guest values(25,0)
    insert into Guest values(19,null)
    insert into Guest values(25,null)
    insert into Guest values(35,null)select * from Guest
    where Age in(
    select Age from Guest
    group by Age
    having count(1)>1
    )
      

  2.   

    create table Guest(
    id int identity,
    Age int,
    Tel int
    )
    insert into Guest values(20,null)
    insert into Guest values(30,null)
    insert into Guest values(20,null)
    insert into Guest values(25,0)
    insert into Guest values(19,null)
    insert into Guest values(25,null)
    insert into Guest values(35,null)select * from Guest
    where Age in(
    select Age from Guest
    group by Age
    having count(1)>1
    )---
    id          Age         Tel         
    ----------- ----------- ----------- 
    1           20          NULL
    3           20          NULL
    4           25          0
    6           25          NULL(所影响的行数为 4 行)
      

  3.   

    或者:
    ------------------------------------------------------------------
    elect 
        a.* 
    from 
        guest a 
    where 
        a.Age in(select Age from guest group by Age having count(*)>1)
      

  4.   

    select * from Guest where 
    Age in(select Age from Guest group by Age having count(1)>1)