我正在尝试从以下查询中获得3个小数位的输出。
我得到的输出是2.2600
如果我在下面的舍入函数中将参数4更改为3,则输出将为2.300
这是不正确的,应该是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
答案 0 :(得分:2)
您可以使用:
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