PostgreSQL - 左连接 generate_series() 和 table

PostgreSQL - left join generate_series() and table

我使用生成系列来创建一系列从 0 到 200 的数字。

我有一个 table,它在名为 polutionmm2 的列中包含以 mm² 为单位的污垢区域。我需要的是将此 table 左连接到生成的系列,但污垢面积必须以 cm² 为单位,因此 /100。我无法完成这项工作,因为我不知道如何将 table 连接到没有名称的系列。

这是我目前所拥有的:

select  generate_series(0,200,1) as x,  cast(p.polutionmm2/100 as char(8)) as metric   
from x
    left join polutiondistributionstatistic as p on metric = x

错误:关系 X 不存在

这是一些示例数据:https://dbfiddle.uk/?rdbms=postgres_13&fiddle=3d7d851887adb938819d6cf3e5849719

我需要的是第一列 (x) 从 0 一直计数到 200,并且在有匹配值的地方显示在第二列中。

像这样:

x, metric
0, 0
1, 1
2, 2
3, null
4, 4
5, null
... , ...
... , ...
200, null

你可以把generate_series()放在FROM里。所以,我想你想要这样的东西:

select gs.x, cast(p.polutionmm2/100 as char(8)) as metric
from generate_series(0,200,1) gs(x) left join
     p
     on gs.x = (p.polutionmm2/100);

我想您的查询还有更多内容,因为这并没有多大用处。