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
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