表employee(name,salary)用sql语句找出salary第二大的值(包括重复值)。请问各位帮忙一下好吗?
谢谢了!

解决方案 »

  1.   


    create proc sp_GetSecond
    as
    --查到最大ID
    declare @MaxID  int 
    --查到第二大ID
    declare @SecondID int
            --最大ID
    select @MaxID = max(productid) from newtable 
            --查处比他小的ID
            select @SecondID = max(productid) from newtable where productid < @MaxID 
            --查处是这个ID的所有记录
            select * from newtable where productid = @SecondIDexec sp_GetSecond