如何转换为3小数点

时间:2014-12-17 23:00:42

标签: sql mysqli formatting format

我创建了这个查询以查找行驶里程的AVG,但是我很难将数据格式化为3个小数点。

49.614112472330234

SELECT AVG(Mileage_Used)/SUM(time_to_sec(timediff(Lesson_Finish_Time,Lesson_Time))/3600) as Mileage_per_hour from LESSONS;

1 个答案:

答案 0 :(得分:1)

将值转换为具有正确精度的十进制类型:

select cast(<yourvalue> as decimal(10,3))

在你的情况下:

SELECT cast(AVG(Mileage_Used)/SUM(time_to_sec(timediff(Lesson_Finish_Time,Lesson_Time))/3600) as decimal(10,3)) as Mileage_per_hour 
from LESSONS