round函数在不工作的情况下

mbjcgjjk  于 2021-07-24  发布在  Java
关注(0)|答案(1)|浏览(287)

所以我有下面的问题,我遗漏了一些东西,并更改了问题的名称:

WITH GET_T AS (
Select table.key
       ,COUNT(DISTINCT(T1.ID)) OVER (PARTITION BY(T.KEY)) as Count  
FROM T
     Left Join T1 ON T1.key = T.key
)

SELECT T5.key,
       case when Count > 0 then ROUND(SUM(total_amt) OVER (PARTITION BY(T4.key))/ Count, 3)
           else 0
             end AS total_invoiced_amount
FROM T3
LEFT JOIN T4 ON T4.key = T3.key
LEFT JOIN T5 on T3.id = T4.d

在我的结果集中,总发票金额列没有四舍五入到小数点后三位。我在这里改了什么,所以我一直都有3个小数位
0.000, 80.000, 175.160
目前我得到
105.5时,应为105.500
80当它应该是80.000
应为0.000时为0

e4eetjau

e4eetjau1#

要显示尾随零,必须将值转换为文本:

to_char(case when Count > 0 then ROUND(SUM(total_amt) OVER (PARTITION BY(T4.key))/ Count, 3)
       else 0
         end,'FM999,9999,990.000')

相关问题