Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL: select average of varchar

I would like to make a report that will show the average grade for different tasks.

I am having trouble with how to get the averages. I need to figure out how to convert the grades to floats so that I can take the averages. The grades sometimes have non-numeric or null values, although most values look like "2.0" or "3.5". I can exclude anything that is non-numeric.

This is what I have so far:

Select
GradingScores.task As task,
Avg(Cast((SELECT GradingScores.score WHERE GradingScores.score LIKE '%[^0-9]%')As float)) As averages
From
GradingScores 

I am using FlySpeed SQL Query.

like image 424
Genevieve Ashymov Avatar asked May 04 '26 23:05

Genevieve Ashymov


1 Answers

You could try using IsNumeric

Select
GradingScores.task As task,
Avg(Cast(GradingScores.score as float) As averages
From
GradingScores where IsNumeric(GradingScores.score) = 1
like image 193
etoisarobot Avatar answered May 06 '26 18:05

etoisarobot



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!