在 SQL 中舍入平均值时如何检索小数 [英] How do I retrieve decimals when rounding an average in SQL
本文介绍了在 SQL 中舍入平均值时如何检索小数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的 SQL 语句
Here is my SQL statement
SELECT ROUND(AVG(column_name), 100)
FROM [database].[dbo].[table]
我检索到的答案是 3
,可能的数字范围在 1 - 5
之间,共 908 行.
The answer I retrieve is 3
with a possible range of numbers between 1 - 5
in 908 rows.
我需要它来表示 3.0
或 3.09
.这可能吗?
I need it to say 3.0
or 3.09
. Is this possible?
推荐答案
平均值将与值具有相同的数据类型,因此对值进行转换:
The average will have the same data type as the values, so cast the values:
SELECT ROUND(AVG(CAST(column_name AS FLOAT)), 2) FROM [database].[dbo].[table]
这篇关于在 SQL 中舍入平均值时如何检索小数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文