Postgre SQL中的数值数据类型

时间:2019-01-04 18:13:07

标签: sql postgresql sqldatatypes

当我为PostgreSQL编写代码时。我经常会收到不需要的数字类型,尤其是以'0.12E3'十进制形式。

例如,

with data as (
select created_at::timestamp::date as date,count(*)
from posts
group by created_at::timestamp::date
)
select date, count, sum(count) over
(order by date asc rows between unbounded preceding and current row) as total
from data

这段代码以科学记数法的形式给出了累加和的结果。

即使代码中没有浮点数,为什么也会发生这种情况?而我该如何纠正或避免这种情况发生?

1 个答案:

答案 0 :(得分:0)

使用agragate时,您需要使用别名-

with data as (
  select created_at::timestamp::date as date, count(*) as day_count
  from posts
  group by created_at::timestamp::date
)
select date, day_count, 
       sum(day_count) over (order by date asc rows between unbounded preceding and current row) as total
from data