【问题标题】:Compare one column values for the table in sql比较sql中表的一列值
【发布时间】:2013-07-12 22:24:05
【问题描述】:

我有 X 列的表格。其中之一是 nvarchar(50)。该列的值是这样的:

13-46187(IC)
13-46186(IC)
13-46189
13-46185
13-46184

我想提取/查找列值结尾的最大数字(在本例中为 189)。我该如何做到这一点?

【问题讨论】:

  • 你可以使用子字符串来提取值吗?

标签: sql numbers compare nvarchar highest


【解决方案1】:

这是硬编码的东西。但会给你一些想法..

create table #temp
(
    textfield varchar(50)
)

insert into #temp
select '13-46187(IC)'
UNION
select '13-46186(IC)'
UNION
select '13-46189'
UNION
select '13-46185'
UNION
select '13-46184'


select Max(Convert(int,substring(SUBSTRING(textfield, 6, LEN(textfield)), 1, 3)))
from #temp

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-23
    • 2013-10-11
    • 1970-01-01
    • 2021-07-14
    相关资源
    最近更新 更多