如何在mysql中将类型从varchar转换为int来选择min [英] HOW select min from cast varchar to int in mysql
本文介绍了如何在mysql中将类型从varchar转换为int来选择min的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在mysql中将varchar转换为双精度值
How to convert varchar into double value in mysql
看,我在varchar中有表列,但它只有数字.在这种情况下,我想选择该值的最小最大值.
See, i have table column in varchar but it has only numbers. In that i want to select min max of the value.
请检查以下查询,其中出现语法错误.
Please check the below query, in which I'm getting a syntax error.
select
MAX(CAST(ch1 as INT)) as max_ch1,
MIN(CAST(ch1 as INT)) as min_ch1
from t9;
请参考以下 sqlfiddle
推荐答案
我认为这是您要寻找的:
I think this is what you are looking for:
SELECT
MIN(CAST(CH1 AS SIGNED)),
MAX(CAST(CH1 AS SIGNED))
FROM t9
正在使用SQLFiddle 此处.
Working SQLFiddle here.
您必须将值CAST投射为SIGNED
,它对应于MySQL中的INTEGER
.关于此的更多信息,请此处.
You have to CAST the value as SIGNED
, which corresponds to INTEGER
in MySQL. More information about this, here.
这篇关于如何在mysql中将类型从varchar转换为int来选择min的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文