Multiplying a timestamp data for several times in BigQuery [duplicate]

流过昼夜 提交于 2019-12-25 17:06:21

问题


I have a time-series starting from 2017-01-01 00:00:00 to the end of 2017-12-31 23:00:00 for 1-hour interval. I need to duplicate this 1-year timestamp for 2400 times in the same column. I need help about this one..

Row  Date_time  
1   2017-01-01 00:00:00 UTC
2   2017-01-01 01:00:00 UTC
3   2017-01-01 02:00:00 UTC
4   2017-01-01 03:00:00 UTC
5   2017-01-01 04:00:00 UTC
6   2017-01-01 05:00:00 UTC
7   2017-01-01 06:00:00 UTC
8   2017-01-01 07:00:00 UTC
...........................
...........................

回答1:


You would do this in BigQuery by generating a timestamp array and then unnesting:

 select ts
 from unnest(generate_timestamp_array('2017-01-01 00:00:00', '2017-12-31 23:00:00', interval 1 hour)) ts

You can then get multiple rows with a similar construct:

 select ts
 from unnest(generate_timestamp_array('2017-01-01 00:00:00', '2017-12-31 23:00:00', interval 1 hour)
            ) ts cross join
      unnest(generate_series(1, 2400)) n


来源:https://stackoverflow.com/questions/59305598/multiplying-a-timestamp-data-for-several-times-in-bigquery

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!