SQL Server MAX()问题 [英] SQL Server MAX() Problem
本文介绍了SQL Server MAX()问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
select max(LACode) as M from dbo.tblLeaveApproval where len(LACode)=8
查询结果:
The query results :
LAC-8038
但如果我写的查询如下:
But If I write the query like :
select max(LACode) as M from dbo.tblLeaveApproval
然后结果:
then it results :
LAC-999
请给我一个解决这个问题的方法。为什么会出现这种差异?
Please give me a solution of this problem. Why such kind of difference is occurs?
推荐答案
LACode
列中的数据被评估为字符串因此LAC-9 ...大于LAC-8 ......当你过滤长度时,你将看不到LAC-9xx值,因此LAC-8xxx将是更大的值。
The data in the LACode
column is being evaluated as a string hence LAC-9... is bigger than LAC-8... and when you filter on the length then you will not see the LAC-9xx values hence LAC-8xxx will be the bigger value.
select MAX(CAST(SUBSTR(LACode,5) as integer)) from dbo.tblLeaveApproval;
返回'LAC - '
前缀后的最大数字。
这篇关于SQL Server MAX()问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文