select * from testtable where age = (select max(age) from testtable) or 
age = (select min(age) from testtable)
这样对不?

解决方案 »

  1.   

    declare @t table([name] varchar(10),age int)
    insert into @t select '小红' ,34
    union all select '小李' ,23
    union all select '小宾' ,12
    union all select '小南' ,22select * from @t a where not exists(select 1 from @t where name<>a.name and age>a.age)
    union all
    select * from @t a where not exists(select 1 from @t where name<>a.name and age<a.age)
      

  2.   

    select * from @t where age in(select max(age) from @t)
    union all
    select * from @t where age in(select min(age) from @t)
      

  3.   

    select * from @t a
    where not exists(select 1 from @t where age<a.age)
    or not exists(select 1 from @t where  a.age<age)
      

  4.   

    select * from testtable where age = (select max(age) from testtable) or 
    age = (select min(age) from testtable)呵呵,这个有意思!
    我没测试过,但应该也是可以的!
    思路独特噢,:P
      

  5.   

    select * from testtable where age in(select min(age),max(age) from testtable)
      

  6.   

    bathinmoonwell,xeqtr1982(ShaKa),lxzm1001(*蓝星之梦*)的方法都可以
    to yuncai(BtMan)的不行
    比较喜欢bathinmoonwell的方法
    declare @t table([name] varchar(10),age int)
    insert into @t select '小红' ,34
    union all select '小李' ,23
    union all select '小宾' ,12
    union all select '小南' ,22select * from @t 
    where age = (select max(age) from @t) or 
    age = (select min(age) from @t)
      

  7.   

    select * from testtable 
    where age in(
    select min(age) from testtable
    union all
    select max(age) from testtable
    )
      

  8.   

    select * from @t a
    where not exists(select 1 from @t where age<a.age)
    or not exists(select 1 from @t where  a.age<age)学到新知识。
    呵呵。一般考虑用UNION