9121

HOW select min from cast varchar to int in mysql

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

Answer1:

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.

Answer2:

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

Recommend

  • For each type of function call to route & geom_leg
  • read csv file without header lines in python
  • SQl Query for concating multiple rows with same ids but with different values which having same date
  • How to get latest unique entries from sqlite db with the counter of entries via Django ORM
  • Activating an input field based on checkbox flag in SAPUI5
  • sorting strings using bubblesort in java
  • Finding Minimum hamming distance of a set of strings in python
  • ViewPager with Fragments holding GridView
  • To split a string and to check if they are anagram to each other
  • XSL variable memory usage
  • VB.NET: How do I use coalesce with db column values and nullable types? Or is there a better solutio
  • Jooq casting String to BigDecimal
  • RavenDB indexing errors
  • Multiple Left Join LINQ-to-entities
  • ZipList with Scalaz
  • Alamofire and Reachability.swift not working on xCode8-beta5
  • Suqueries in select clause with JPA
  • Default parameter as generic type
  • Question about instantiating object
  • RxJava debounce by arbitrary value
  • D3 get axis values on zoom event
  • C: Incompatible pointer type initializing
  • Can you perform a UNION without a subquery in SQLAlchemy?
  • JSON response opens as a file, but I can't access it with JavaScript
  • Email verification using google app script and google forms
  • PostgreSQL Query without WHERE only ORDER BY and LIMIT doesn't use index
  • How to avoid particles glitching together in an elastic particle collision simulator?
  • Recording logins for password protected directories
  • Splitting given String into two variables - php
  • Check if a string to interpolate provides expected placeholders
  • Display Images one by one with next and previous functionality
  • How to get next/previous record number?
  • SQL merge duplicate rows and join values that are different
  • Hits per day in Google Big Query
  • FormattedException instead of throw new Exception(string.Format(…)) in .NET
  • Linking SubReports Without LinkChild/LinkMaster
  • apache spark aggregate function using min value
  • XCode 8, some methods disappeared ? ex: layoutAttributesClass() -> AnyClass
  • Sorting a 2D array using the second column C++
  • java string with new operator and a literal