如何获取列中找到的最后一个值并将其存储在变量中? [英] How to get the last value found in a column and store it in variable?

查看:46
本文介绍了如何获取列中找到的最后一个值并将其存储在变量中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何获取列中找到的最后一个值并将其存储在变量中?例如



id不是主键或唯一键。

How to get the last value found in a column and store it in variable? E.g.

id is not primary or unique key.

id  name  age
6   jer   19 
8   mat   30 
9   ben   40 



i将在下面插入这个新列,命名为sis,但首先我要创建的代码会自动找到最后一个更高的数字以及找到最后一个更高的数字。下一个插入的行将增加10.因此,由于找到的最后一个年龄为40,因此下面插入的行的年龄将变为50.


i will insert this new column below, name sis, but first i want to create code that will automatically found the last higher number and when the last higher number found. the next inserted row will increment by 10. so the age of row inserted below will become 50 since the last age found is 40.

10 sis _?_



为了方便起见。我想要一个数据库代码,它将自动找到在年龄中找到的更高/更大的数字,一旦代码找到更高的数字,我将添加新行。它将增加(ed)10。


To make it easier. i want a database code that will automatically found the higher/large number found in age and once the code found the higher number i will add new row. it will increment(ed) by 10.

推荐答案

Select TOP 1 age from table_name ORDER BY age DESC



将此输出变为变量,将其递增10,输入在你想要的领域。



如果仍有任何疑问,请再次打电话。



问候......:笑:


Take this output in variable,increment it by 10,enter it in your desired field.

Call again if still have any doubts.

Regards..:laugh:


试试这段代码:

@num = max(age);
Try this code:
@num = max(age);


这篇关于如何获取列中找到的最后一个值并将其存储在变量中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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