在Sql中获取最大值 [英] Getting maximum value in Sql

查看:83
本文介绍了在Sql中获取最大值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我有一个数据REGCOUNT_T
--------------------------
1
10
2
3
4
5
6
7
8
9

这是我的SQL命令:
从FEEDBACK_DATA中选择MAX(REGCOUNT_T)作为运行计数

在下一次执行后,我仍然得到9作为最大值.如何获得10的值,以便在我加1后下一个运行计数为11?

Hye everybody,

I have a data REGCOUNT_T
--------------------------
1
10
2
3
4
5
6
7
8
9

This is my SQL command:
SELECT MAX(REGCOUNT_T) AS RUNCOUNT FROM FEEDBACK_DATA

After next execution, I still get 9 as the max value. How to get the 10 value so that the next running count will be 11 after I add by 1?

推荐答案

原因是REGCOUNT_T 列的数据可能为文本类型,在这种情况下10排在9之前,因此返回9作为最大值.
要获得正确的结果,请将REGCOUNT_T的值转换为如下所示的数字类型
The reason is that the data of REGCOUNT_T column may be in text type, in which case 10 comes before 9, so 9 is returned as maximum value.
To get the correct result either convert the value of REGCOUNT_T to numeric type as below
SELECT MAX(CONVERT(INT,REGCOUNT_T)) AS RUNCOUNT FROM FEEDBACK_DATA


或将数据类型REGCOUNT_T设置为类似INT的数字类型.


or set the data type REGCOUNT_T to a numeric type like INT.


这篇关于在Sql中获取最大值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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