34,838
社区成员




select * from ta a where not exists(select 1 from ta where num> a.num)
if object_id('tempdb..#') is not null
drop table #
create table #(num int not null)
insert into #
select 1
union all
select 2
union all
select 3
union all
select 4
union all
select 5
union all
select 5
--1
select top 1 num
from #
order by num desc
--2
select distinct num
from # a
where not exists(select top 1 1
from # where num>a.num)
--3
declare @i int
declare @temp int
declare @max int
set @i=0
set @temp=0
set @max=0
declare cur cursor local for
select num from #
open cur
fetch next from cur into @i
while @@fetch_status=0
begin
set @temp = @i
if(@temp>@max)
set @max=@temp
else
set @max=@max
fetch next from cur into @i
end
select @max
close cur
deallocate cur
--6
declare @num1 int
update @a
set @num1=case when @num1 is null then num
when @num1<num then num
else @num1
end
select @num1