Skip to content
Advertisement

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?

Advertisement

Answer

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.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement