LAST()函数返回所选列的最后一个值. [英] The LAST() function returns the last value of the selected column.

查看:229
本文介绍了LAST()函数返回所选列的最后一个值.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最后一条记录数据库如何退回
错误:"last"不是公认的内置函数名称.

How the last record database back
error:''last'' is not a recognized built-in function name.

public string lastreclettr(string a)
     {
         string s = "";
         command.CommandText = "SELECT last(tnum)  FROM sendletter";
         connection.Open();
         command.Parameters.AddWithValue("@tnum",a);
         SqlDataReader reader = command.ExecuteReader();
        reader.Read();
         if (reader.HasRows)
             s= reader[0].ToString();
         return s;
     }

推荐答案


您可以尝试
Hi,
you can try
command.CommandText = "
SELECT TOP 1 rel.tnum  
FROM (SELECT tnum, ROW_NUMBER() OVER(ORDER BY (SELECT 1)) AS row_nr FROM sendletter) AS rel ORDER BY rel.row_nr DESC";

,它将返回您sendletter表中的最后一项.
初始化时,ROW_NUMBER()将为内部选择中返回的每个ROW提供一个数字(因此row_nr将为[1 ... n]).然后,您可以按相反顺序订购并选择TOP 1,这将为您提供最后一个项目.希望这会有所帮助.
问候

, it will return you the last item in the sendletter table.
Initilly the ROW_NUMBER() will give a number for each ROW returned in the inner select (thus row_nr will be [1...n]). Then you can order it inversely and select the TOP 1, which will give you the last item. Hope this helps.
Regards


这篇关于LAST()函数返回所选列的最后一个值.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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