How to round an average to 2 decimal places in PostgreSQL?

后端 未结 8 1500
渐次进展
渐次进展 2020-11-30 18:01

I am using PostgreSQL via the Ruby gem \'sequel\'.

I\'m trying to round to two decimal places.

Here\'s my code:

SELECT ROUND(AVG(some_column)         


        
8条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-30 18:11

    According to Bryan's response you can do this to limit decimals in a query. I convert from km/h to m/s and display it in dygraphs but when I did it in dygraphs it looked weird. Looks fine when doing the calculation in the query instead. This is on postgresql 9.5.1.

    select date,(wind_speed/3.6)::numeric(7,1) from readings;
    

提交回复
热议问题