如何选择最后一行记录 [英] How to select last row record

查看:104
本文介绍了如何选择最后一行记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好。那我想选择最后一行记录,下面是我的代码但是没有得到结果我想要任何帮助将不胜感激。



我感谢您努力帮助我解决这个问题。我已经尝试了你提供的所有解决方案,但仍然没有得到我想要的结果。因此,让我使用下面的示例数据来解释事情。



示例

LedgerNumber LedgerName金额

4黄金300

7大米280

7大米500

4黄金80

4黄金120

7大米550



这里的样本记录有六行,三列。假设我想选择名为Gold的LedgerName的最后一笔金额。此样本数据中ledgerName Gold的最后一个金额为120,但表中的最后一个金额为550,其中有一个名为Rice的分类帐名称,而不是目标。我希望这个解释能让读者更好地理解。



Hi everyone out there.Please I want to select the last row record and below is the code I have but am not getting the result I want any help will be grateful.

I appreciate all your effort in trying to help me solve this problem. I have try all the solutions you have provided and am still not getting the result I want. So let me use sample data below to explain things very well.

Example
LedgerNumber LedgerName Amount
4 Gold 300
7 Rice 280
7 Rice 500
4 Gold 80
4 Gold 120
7 Rice 550

Here the sample records above has six rows with three columns. Let say I want to select the last Amount with a LedgerName called Gold. The last amount in this sample data for ledgerName Gold is 120 but the last amount in the table is 550 which has a ledgername called Rice and that is not the target. I hope this explanation will give readers better understanding.

Select Top (1) Amount From Transactions
Where LedgerName = 'ABC'
Order By LedgerName DESC





谢谢。



Thanks.

推荐答案

尝试这个..它的工作原理/>
try this.. it works
Select Top (1) Amount From Transactions
Where LedgerName = 'ABC'
Order By Amount DESC


尝试

Try
Select Top (1) Amount From Transactions<br />
Where LedgerName = 'ABC'<br />
Order By Amount DESC





用<$替换 LedgerName C $ C>金额。由于您选择ABC作为 LedgerName ,因此无论如何它都是相同的。



Replace LedgerName with Amount. Since you choose ABC as the LedgerName, it is the same anyway.


如果您真的对此解决方案感到困惑。离开它只是做它LINQ它很简单

无需任何订单只需使用Last或LastOrDefault方法它将返回你最后的记录表

获取更多info

http://www.dotnetperls.com/lastordefault [ ^ ]

播放与倒数和 - lastordefault合LINQ到entities.aspx [ ^ ]
if you are really confuse with this solution. THen leave it just do it LINQ and it's simple
no need to order by any thing Just use Last or LastOrDefault method it will return you last record of the table
Get more info
http://www.dotnetperls.com/lastordefault[^]
play-with-last-and-lastordefault-in-linq-to-entities.aspx[^]


这篇关于如何选择最后一行记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆