Search code examples
sqlroundingpgadmin-4

Need assistance in using round on a current query


SELECT
    (TS_LEXIZE('english_stem',
               UNNEST(STRING_TO_ARRAY(
                   REGEXP_REPLACE(feedback, '[^a-zA-Z]+', ' ', 'g'),
                   ' ')
               )))[1] AS token,
    AVG(rating) AS avg_rating
FROM customer_survey 
GROUP BY 1
HAVING COUNT(1) >= 3
ORDER BY 2 DESC
;

I have the following query where would you add ROUND () if you want to limit the rating to 2 decimal places?


Solution

  • SELECT
        (TS_LEXIZE('english_stem',
                   UNNEST(STRING_TO_ARRAY(
                       REGEXP_REPLACE(feedback, '[^a-zA-Z]+', ' ', 'g'),
                       ' ')
                   )))[1] AS token,
        ROUND(AVG(rating)) AS avg_rating
    FROM customer_survey 
    GROUP BY 1
    HAVING COUNT(1) >= 3
    ORDER BY 2 DESC
    ;
    

    By adding the round before the avg I got it.