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

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

    Try with this:

    SELECT to_char (2/3::float, 'FM999999990.00');
    -- RESULT: 0.67
    

    Or simply:

    SELECT round (2/3::DECIMAL, 2)::TEXT
    -- RESULT: 0.67
    

提交回复
热议问题