我正在使用Postgresql 9.2
假设我有桌子:
id date click_count registration_count
serial timestamp bigint bigint
我写了以下问题:
select date, sum(click_count),
sum(registration_count),
(CASE
WHEN (not sum(click_count) = 0)
THEN sum(registration_count)/sum(click_count)*100
ELSE 0
END) as convert
from myTbl
它有效,但不正确。问题是我需要获得算术运算的双重结果,但在结果中它具有bigint
类型。有办法解决这个问题吗?
答案 0 :(得分:1)
如何使用cast()
?
select date, sum(click_count),
sum(registration_count),
(CASE WHEN (not sum(click_count) = 0)
THEN cast(sum(registration_count) as double)/sum(click_count)*100
ELSE 0.0
END) as convert
from myTbl