select a.a1 from A a where(select a1 from A where a1>a.a1) 语法错误 select a.a1 from A a where not exists(select a1 from A where a1>a.a1) 得到最大值 select max(a1) from A
create table #a(a int,b int) insert into #a select 1,16 insert into #a select 2,15 insert into #a select 3,14 insert into #a select 4,13 insert into #a select 5,12 insert into #a select 6,11 select a.a from #a a where not exists(select a from #a where a>a.a) a ----------- 6(所影响的行数为 1 行)
select max(a1) from A, 最大值
select a.a1 from A a where not exists(select a1 from A where a1>a.a1) 得到最大值 select a.a1 from A a where exists(select a1 from A where a1>a.a1) 得到除最大值以外的值
where(select a1 from A where a1>a.a1) 语法错误
select a.a1 from A a
where not exists(select a1 from A where a1>a.a1)
得到最大值
select max(a1) from A
insert into #a select 1,16
insert into #a select 2,15
insert into #a select 3,14
insert into #a select 4,13
insert into #a select 5,12
insert into #a select 6,11
select a.a from #a a
where not exists(select a from #a where a>a.a)
a
-----------
6(所影响的行数为 1 行)
where not exists(select a1 from A where a1>a.a1)
得到最大值
select a.a1 from A a
where exists(select a1 from A where a1>a.a1)
得到除最大值以外的值