Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

SQL min and max function not displaying proper results

I am having a problem with using the MIN and MAX function in Microsoft SQL Server

The problem is regarding MIN and MAX functions displaying the results incorrectly.

My query is like this:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

SELECT 
    MIN(compression_ratio) AS minimum_cr,
    MAX(compression_ratio) AS maximum_cr
FROM dbo.C4m3practice 

and it returns the MIN value 10 and MAX value 9.6, which doesn’t make sense and is also both wrong.
I’ll attach a picture below. What am I doing wrong?

IMG

>Solution :

Seems like compression_ratio of type varchar(), you will need to convert your column to float

Try this :

SELECT 
    MIN(CAST(compression_ratio as float)) AS minimum_cr,
    MAX(CAST(compression_ratio as float)) AS maximum_cr
FROM dbo.C4m3practice 
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading