SQL BigQuery - 如何将日期 (2020-11-14 16:04:15 UTC) 转换为工作日值 (0-6)
SQL BigQuery - How to convert date(2020-11-14 16:04:15 UTC) to WEEKDAY value (0-6)
我目前正在解决这个问题。这是一些相关的 documentation
我有一个时间日期列,格式为 { 2020-11-14 16:04:15 UTC }。我想以一个对应于星期几的整数 1-7 的列结束。 1 = 星期日和 7 = 星期六。
目前,我有这个在特定日期有效。
SELECT EXTRACT(DAYOFWEEK FROM DATE '2013-12-25') AS the_day
如何将此函数应用于整个列?
感谢您的帮助。
SQL BigQuery
改编自日期函数的文档'Extract'示例 2。
https://cloud.google.com/bigquery/docs/reference/standard-sql/date_functions?hl=ar-YE#extract
SELECT
date,
EXTRACT(DAYOFWEEK FROM date) AS the_day
FROM UNNEST(GENERATE_DATE_ARRAY('2015-12-23', '2016-01-09')) AS date
ORDER BY date;
下面是例子。
WITH
org_table AS (
SELECT DATE('2013-12-25') as org_col
UNION ALL SELECT '2013-12-26'
UNION ALL SELECT '2013-12-28'
UNION ALL SELECT '2013-12-29'
)
SELECT
org_col,
EXTRACT(DAYOFWEEK FROM org_col) AS the_day
FROM org_table
ORDER BY org_col
;
p.s。
要应用现有查询,请替换 org_table.
WITH
org_table AS (
SELECT `your_column` as org_col
FROM `your_table`
)
...
我目前正在解决这个问题。这是一些相关的 documentation
我有一个时间日期列,格式为 { 2020-11-14 16:04:15 UTC }。我想以一个对应于星期几的整数 1-7 的列结束。 1 = 星期日和 7 = 星期六。
目前,我有这个在特定日期有效。
SELECT EXTRACT(DAYOFWEEK FROM DATE '2013-12-25') AS the_day
如何将此函数应用于整个列?
感谢您的帮助。
SQL BigQuery
改编自日期函数的文档'Extract'示例 2。 https://cloud.google.com/bigquery/docs/reference/standard-sql/date_functions?hl=ar-YE#extract
SELECT
date,
EXTRACT(DAYOFWEEK FROM date) AS the_day
FROM UNNEST(GENERATE_DATE_ARRAY('2015-12-23', '2016-01-09')) AS date
ORDER BY date;
下面是例子。
WITH
org_table AS (
SELECT DATE('2013-12-25') as org_col
UNION ALL SELECT '2013-12-26'
UNION ALL SELECT '2013-12-28'
UNION ALL SELECT '2013-12-29'
)
SELECT
org_col,
EXTRACT(DAYOFWEEK FROM org_col) AS the_day
FROM org_table
ORDER BY org_col
;
p.s。 要应用现有查询,请替换 org_table.
WITH
org_table AS (
SELECT `your_column` as org_col
FROM `your_table`
)
...