【发布时间】:2021-08-20 23:12:46
【问题描述】:
我有一个如下查询,它会生成下表:-
select * from temp_3
bucket values
OTIF+2 319
OTIF 24987
null 1347
OTIF+>2 515
OTIF+1 552
现在我需要这些值占我编写以下查询的值总和的百分比:-
select sum(values) as total into temp_1 from temp_3
select bucket, (values/(select total from temp_1)) as score from temp_3
但这导致了以下结果:-
bucket values
OTIF+2 0
OTIF 0
null 0
OTIF+>2 0
OTIF+1 0
谁能告诉我我们如何有效地将其转换为百分比形式?以及我哪里出错了?
【问题讨论】:
-
整数运算,5/20 产生 0。将其转换为十进制,例如
values * 1.0/(select total from temp_1)
标签: sql derived-column