1

I'm trying to get an output of 3 decimal places out of the below query.

the output i'm getting is 2.2600

if I changed the parameter 4 to be 3 in round function below, the output will be 2.300

which is incorrect, it should be 2.26

Select date(time), 

    round((count(case WHEN status='404 NOT FOUND' THEN 1 END))
    /
    (count(*))::numeric,4) * 100 as error_percentage

from log GROUP BY date(time)
ORDER BY error_percentage DESC
2
  • use ceil function instead of round Commented Mar 31, 2019 at 8:52
  • That shows the number rounded as whole. I still want to show the first 3 decimal places Commented Mar 31, 2019 at 9:00

1 Answer 1

2

You could use:

SELECT date(time), 
    ROUND(100.0 * (count(*) FILTER(WHERE status='404 NOT FOUND'))/(count(*)),3) 
    as error_percentage
FROM log 
GROUP BY date(time)
ORDER BY error_percentage DESC
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.