gpt4 book ai didi

sql - Postgresql ROUND 函数

转载 作者:行者123 更新时间:2023-11-29 13:40:25 24 4
gpt4 key购买 nike

我尝试四舍五入这个查询,但我的结果有 10 位小数。我已经尝试了 DECIMAL() 函数、CAST()ROUND() 并且它仍然不起作用。我需要 2 位小数。

select type, count(id) filter ( where type ilike 
'private') as "number of applications",
count(id) filter ( where type ilike 'private' and
type ilike 'paid') as "number of paid applications",
(count(id) filter ( where type ilike 'private' and
status ilike 'paid')
/round(count(id) filter (where type ilike 'private')) *
(100)) as "percent of paid applications"
from applications
where type ilike 'private'
group by type
union
select type, count(id) filter ( where type ilike
'business') as "number of applications",
count(id) filter ( where type ilike 'private' and
status ilike 'paid') as "number of paid applications",
(count(id) filter ( where type ilike 'business' and
status ilike 'paid')
/round(count(id) filter (where type ilike
'business')) * (100)) as "percent of paid applications"
from applications
where type ilike 'business'
group by type

最佳答案

round(yourvalue,2) 应该如你所愿

例如select round(12.1451124569,2) 一个具有 10 位小数精度的数字作为第一个参数返回 12.15

关于sql - Postgresql ROUND 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56261658/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com