select num
from test a
where not exists(select 1 from test where num<a.num)

解决方案 »

  1.   

    declare cursor_c cusor from
       select num from test a
    declare @min int,
            @temp int
          set @temp =0
    open cursor_c
    fetch cursor_c into  @min
    while @@fetch_status=0
    begin
       if @min<@temp 
       set @temp=@min
       fetch cursor_c into  @min     
    end
    close cursor_c
    deallocate cursor_c
    print @temp
      

  2.   

    declare cursor_c cusor from
       select num from test a
    declare @min int,
            @temp int
          set @temp =0
    open cursor_c
    fetch cursor_c into  @min
    while @@fetch_status=0
    begin
       if @min<@temp 
       set @temp=@min
       fetch cursor_c into  @min     
    end
    close cursor_c
    deallocate cursor_c
    print @temp
      

  3.   

    declare cur_tab cursor 
    for
    select iid from test3
    open cur_tab
    declare @idvalue int
    declare @i int
    fetch next from cur_tab into @idvalue
    set @i=@idvalue
    while @@fetch_status=0
    begin
    if @i<@idvalue  set @i=@idvalue
    fetch next from cur_tab into @idvalue
    end
    print @i
      

  4.   

    用循环比游标快些。
    SELECT * from test
    declare @maxrow int
    set @maxrow=@@rowcount
    declare @num int
    set @num=(select top 1 num from test)
    declare @i int
    set @i=2
    while @i<=@maxrow
    Begin
    if exists (select * from test where num<@num)
    set @num=(select top 1 num from test where num<@num)
    set @i=@i+1
    End
    select @num
      

  5.   

    : xluzhong(打麻将一缺三,咋办?) ( ) 信誉:100 
    的答案很正确.select num
    from test a
    where not exists(select 1 from test where num<a.num)另外还有select num
      from test a
     where a.num > all (select num from test where num <> a.num)这个的效率没有上面的好。 数据量大时效率差异越明显.