简体   繁体   English

如何在 sql 的组语句中显示小数位

[英]How to display decimal places in group statetement in sql

SELECT DISTINCT date,

       type,

       id,

       process,

       PERCENTILE_DISC(0.90) within group(ORDER BY duration/60000) OVER (PARTITION BY date,type,id,process) AS top90

FROM table

It returned like follow.它像跟随一样返回。

date       id    type  process top90
2021-05-19  a      X    A       6
2021-05-19  b      Y            
2021-05-19  c      Z    A       7

But my desired result is like following to display up to 2 decimal places.但我想要的结果就像下面显示最多 2 个小数位。

date       id    type  process top90
2021-05-19  a      X    A       6.36
2021-05-19  b      Y            
2021-05-19  c      Z    A       7.42

I tried cast(duration/60000,real) but it returned same result..我试过cast(duration/60000,real)但它返回了相同的结果..

If someone has opinion, please let me know.如果有人有意见,请告诉我。

Thanks谢谢

  1. If duration is an integer or bigint , duration / 60000 will be an integer division and truncate the result.如果durationintegerbigint ,则duration / 60000将是 integer 除法并截断结果。

    Use duration / 60000.0 to avoid that.使用duration / 60000.0来避免这种情况。

  2. percentile_disc will return the existing value closest to the specified percentile. percentile_disc将返回最接近指定百分位数的现有值。 Use percentile_cont to interpolate.使用percentile_cont进行插值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM