SQL:使用附加的 运行 序列字段复制行

SQL: duplicating rows with an additional running sequence field

我正在尝试创建一个 select 语句来将每个唯一行(通过 'location' 字段)复制 361 次(0 到 360)。还创建了一个附加列来显示序列(0 到 360)。这样做的目的是使用半径和度数字段计算每个纬度和经度周围的坐标,以将其呈现为 Tableau 中的圆。

这是原始样本 table。

这是最终需要的输出。

有人能帮忙吗?

以逗号分隔的示例数据~

Location,Radius,Latitude,Longitude
A,500,31.4799,88.38783
B,1000,35.580941,77.01125
C,800,37.492528,88.797115

EDIT: 原来table.

中有50多行

我认为 Vertica 没有 Postgres 的 generate_series()。你可以模拟它,如果你有一个至少有 361 行的 table:

with n as (
      select row_number() over () - 1 as n
      from (select s.* from sample s limit 361) s
     )
select s.*, n.n as degress
from sample s cross join
     n;

在 Vertica 中,order by 对于 row_number() 函数是可选的。

您还可以在 Vertica 中滥用 time series 来生成一个序列,而根本不需要任何表格:

with mydegrees as (
    SELECT extract( epoch from slice_time - to_timestamp(0) ) Degree
    from ( select to_timestamp(0) ts 
           union all
           select to_timestamp(0) + interval '360 seconds' ) x   
    TIMESERIES slice_time AS '1 second' OVER (ORDER BY ts)
) 
select t.*, d.Degree
from mytable t cross join 
     mydegrees d;

基本上我们只是设置一个0到360秒的start/to时间戳,然后我们为每个时间片提取'seconds since epoch 0'(使用1秒时间片)。