我觉得我错过了一些明显的东西.我试图测试分发random().这是表格:
create table test (
id int,
random_float float,
random_int int
);
Run Code Online (Sandbox Code Playgroud)
这是我想要做的:
truncate table test;
insert into test (id)
values (generate_series(1,1000));
update test
set
random_float = random() * 10 + 1;
update test
set
random_int = trunc(random_float);
select
random_int,
count(random_int) as Count,
cast( count(random_int) / max(id) as float) as Percent
from test
group by random_int
order by random_int;
Run Code Online (Sandbox Code Playgroud)
但是,"Percent"列为每条记录返回零.我尝试将其转换为float,作为十进制,我尝试将random_int列更改为十进制而不是整数,总是相同的结果.
对于我做错了什么的任何见解?