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

后端 未结 8 1519
渐次进展
渐次进展 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:19

    you can use the function below

     SELECT TRUNC(14.568,2);
    

    the result will show :

    14.56
    

    you can also cast your variable to the desire type :

     SELECT TRUNC(YOUR_VAR::numeric,2)
    

提交回复
热议问题