<table><tbody><tr><th>Row</th><th>Identifier</th><th>date_time</th><th>HvacMode</th><th>CalendarEvent</th></tr><tr><td>1</td><td>a578bb21941003e7a58a399375b20f274fab5233</td><td>2020-10-31 14:50:00 UTC</td><td>heat</td><td> </td></tr><tr><td>2</td><td>683227685eb44f9d231d511e8ae5255ecc1b71fb</td><td>2019-08-19 02:00:00 UTC</td><td>cool</td><td> </td></tr><tr><td>3</td><td>1afd0d7a8408458d39dde687e1218f2948907c4b</td><td>2021-07-19 19:40:00 UTC</td><td>auto</td><td> </td></tr><tr><td>4</td><td>607db2c120782353da1539a008956301341d54c9</td><td>2020-08-29 16:50:00 UTC</td><td>cool</td><td> </td></tr><tr><td> </td><td> </td><td> </td><td> </td><td> </td></tr></tbody></table>
我想獲取一年中每天早上 7 點到晚上 7 點(7:00-19:00)特定時間段的資料。我有一個格式為 2017:01:01 00:00:00 (示例)的日期時間欄位。這里有點新手。我知道如何提取特定日期范圍,但我不知道如何提取特定時間的日期范圍。在 BigQuery 中處理非常大的資料集。任何幫助都會有所幫助。樣本資料影像
uj5u.com熱心網友回復:
如果我理解您的問題,您正在嘗試按 7-7 時間段過濾每天的資料。試試下面的例子:
with sample_data as (
SELECT ts FROM UNNEST(generate_timestamp_array('2021-01-01 00:00:00', '2021-03-01 00:00:00', INTERVAL 1 hour)) as ts
)
select *
from sample_data
where
extract(year from ts) = 2021
and extract(hour from ts) between 7 and 19;
使用提取功能,您可以從時間戳中提取小時,然后在兩者之間進行過濾。有關提取功能的更多資訊,請參閱以下檔案:https : //cloud.google.com/bigquery/docs/reference/standard-sql/timestamp_functions#extract
uj5u.com熱心網友回復:
全部;
這適用于我需要的資料。謝謝您的幫助。下面的片段給了我一月份的白天時間。
select *
from sample_data where extract(hour from date_time) between 7 and 19
AND date_time between '2017-01-01 00:00:00' and '2017-01-31 23:59:00';
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/382535.html
