SQL CAST() inside AVG() for decimal valueThe SQL AVG() function returns the average value with default decimal places. The CAST() is used to increase or decrease the decimal places of a value. The CAST() function is much better at preserving the decimal places when converting decimal and numeric data types.
To exclude entries with “0”, you need to use NULLIF() with function AVG().
The AVG() function returns the average value of a numeric column.
Try
Select
AVG(Cast(variable as Float)),
SUM(variable)
From
Table
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With