选择数据库中的最后一组记录 [英] Select last group of records in database
问题描述
亲爱的数据库专家,
我在MSSQL 2012中有一个表,我想读取最后一组记录(可以是1条记录或更多),基于一个提交。
据我所知,如果我想选择最后一条记录我可以使用下面的sql ,,但是用于读取一组记录(数量为记录取决于一个字段的值),我不知道
Dear Database Experts,
I have a table in MSSQL 2012 and I want to read last group of records(It can be 1 record or more) base on the one filed.
as far as I know if I want to select last record I can use the below sql ,, but for reading a group of records (number of records depends on the value of one field), I don't have idea
SELECT TOP 1 DEBIT,TRANS_DESC FROM LGR WHERE REFERENCE="8888" ORDER BY TRANS_NO DESC
样本表
非常感谢您的帮助
在此先感谢
sample table
Your help is greatly appreciated
Thanks in advance
推荐答案
您好,
你盘旋了trans_Desc 182如果这意味着你想要选择这个标准...
你可以这样做
Hi,
you have circled trans_Desc 182. if that means you want to select on this criteria...
you can do this as
SELECT * FROM LGR WHERE TRANS_DESC
in ( select Max(TRANS_DESC) from LGR )
它将显示一组记录..
如果你的目的是差异的话。那么请详细解释目的。
it will display a group of records..
and if your purpose is something diff. then please explain little more about the purpose.
这篇关于选择数据库中的最后一组记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!