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)
select * from @t where age in(select max(age) from @t) union all select * from @t where age in(select min(age) from @t)
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)
select * from testtable where age = (select max(age) from testtable) or age = (select min(age) from testtable)呵呵,这个有意思! 我没测试过,但应该也是可以的! 思路独特噢,:P
select * from testtable where age in(select min(age),max(age) from testtable)
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)
select * from testtable where age in( select min(age) from testtable union all select max(age) from testtable )
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
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)
union all
select * from @t where age in(select min(age) from @t)
where not exists(select 1 from @t where age<a.age)
or not exists(select 1 from @t where a.age<age)
age = (select min(age) from testtable)呵呵,这个有意思!
我没测试过,但应该也是可以的!
思路独特噢,:P
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)
where age in(
select min(age) from testtable
union all
select max(age) from testtable
)
where not exists(select 1 from @t where age<a.age)
or not exists(select 1 from @t where a.age<age)学到新知识。
呵呵。一般考虑用UNION