Как получить вторую последнюю запись в SQL
Hi, i have below table and the records are
CREATE TABLE [dbo].[Trn_ATN]( [ATN_No] [numeric](18, 0) NULL, [ATN_Number] [nvarchar](50) NULL, [ATN_Date] [date] NULL, [ATN_AstNo] [numeric](18, 0) NULL ) ON [PRIMARY] GO
datas are insert into Trn_ATN (ATN_No,ATN_Number,ATN_Date,ATN_AstNo) values(1,'A-1','2016-01-01',1) insert into Trn_ATN (ATN_No,ATN_Number,ATN_Date,ATN_AstNo) values(2,'A-1','2016-01-01',2) insert into Trn_ATN (ATN_No,ATN_Number,ATN_Date,ATN_AstNo) values(3,'A-2','2016-01-02',1) insert into Trn_ATN (ATN_No,ATN_Number,ATN_Date,ATN_AstNo) values(4,'A-4','2016-01-02',2) insert into Trn_ATN (ATN_No,ATN_Number,ATN_Date,ATN_AstNo) values(5,'A-3','2016-01-03',1)
what was the last ATN_Date and ATN_AstNo. below is the result what i want. ATN_No ATN_Number ATN_Date ATN_AstNo 2 A-1 1/1/2016 2 3 A-2 1/2/2016 1 Thanks Basit.
Что я уже пробовал:
я пробовал ниже запроса
SELECT TOP 2 * FROM dbo.Trn_ATN WHERE EXISTS ( SELECT TOP 2 ATN_No ,ATN_Date ,ATN_AstNo FROM dbo.Trn_ATN ORDER BY ATN_Date,ATN_AstNo DESC )
потом пришел результат
ATN_No ATN_Number ATN_Date ATN_AstNo 1 A-1 2016-01-01 1 2 A-1 2016-01-01 2