How to convert varchar into double value in mysql
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;
Please refer to below sqlfiddle
I think this is what you are looking for:
SELECT MIN(CAST(CH1 AS SIGNED)), MAX(CAST(CH1 AS SIGNED)) FROM t9
Working SQLFiddle here.
You have to CAST the value as
SIGNED, which corresponds to
INTEGER in MySQL. More information about this, here.
You can force an automatic numeric cast when adding a operation like multiplication
select MAX(ch1*1) as max_ch1, MIN(ch1*1) as min_ch1 from t9