红移计算输出不包括所有小数结果

时间:2021-08-16 23:08:15

I'm trying to do something really quite basic to catch a kind of percentage among two columns in redshift. However, when I run the query with an example the result is simply zero because the decimals are not being covered.

我正在尝试做一些非常基本的事情来捕捉redshift中两列中的某种百分比。但是,当我使用示例运行查询时,结果只是零,因为小数未被覆盖。

code:

码:

select 1701 / 84936;

Output:

输出:

红移计算输出不包括所有小数结果

I tried :

我试过了 :

select cast(1701 / 84936 as numeric (10,10));

but the result was 0.0000000000.

但结果是0.0000000000。

How could I solve this silly thing? thanks so much.

我怎么能解决这个愚蠢的事情?非常感谢。

1 个解决方案

#1


3  

It is integer division. Make sure that at least one argument is: NUMERIC(accurate data type)/FLOAT(caution: it's approximate data type):

它是整数除法。确保至少有一个参数是:NUMERIC(准确数据类型)/ FLOAT(警告:它是近似数据类型):

/ division (integer division truncates the result)

/ division(整数除法截断结果)

select 1701.0 / 84936;
-- or
SELECT 1.0 * 1701 / 84936;
-- or
SELECT CAST(1701 AS NUMERIC(10,4))/84936;

DBFiddle Demo

DBFiddle演示

#1


3  

It is integer division. Make sure that at least one argument is: NUMERIC(accurate data type)/FLOAT(caution: it's approximate data type):

它是整数除法。确保至少有一个参数是:NUMERIC(准确数据类型)/ FLOAT(警告:它是近似数据类型):

/ division (integer division truncates the result)

/ division(整数除法截断结果)

select 1701.0 / 84936;
-- or
SELECT 1.0 * 1701 / 84936;
-- or
SELECT CAST(1701 AS NUMERIC(10,4))/84936;

DBFiddle Demo

DBFiddle演示