如何在 Bigquery 中创建临时 table
How to create a Temporary table in Bigquery
我一直在尝试在以下查询中使用 CREATE TEMPORARY TABLE 和 WITH 语句构建临时 Table。到目前为止,我还没有得到任何积极的结果,我也不知道发生了什么。
在最后一行,错误警报显示:“语法错误:应为“(”或“,”或关键字 SELECT,但在 [28:62] 处结束了脚本”
WITH analysis_fall_2021_season AS
(SELECT
start_station_name,
end_station_name,
EXTRACT (DATE FROM started_at) AS start_date,
EXTRACT (DATE FROM ended_at) AS end_date,
EXTRACT (TIME FROM started_at) AS start_time,
EXTRACT (TIME FROM ended_at) AS end_time,
DATETIME_DIFF (ended_at,started_at, MINUTE) AS total_lenght,
member_casual
FROM
(SELECT
fall_analysis.ride_id,
fall_analysis.started_at,
fall_analysis.ended_at,
fall_analysis.start_station_name,
fall_analysis.end_station_name,
fall_analysis.member_casual
FROM
`ciclystic.cyclistic_seasonal_analysis.fall_202010` AS fall_analysis
INNER JOIN
`ciclystic.cyclistic_seasonal_analysis.fall_202011` AS fall_202011
ON
fall_analysis.member_casual = fall_202011.member_casual
INNER JOIN
`ciclystic.cyclistic_seasonal_analysis.fall_202012` AS fall_202012
ON
fall_analysis.member_casual = fall_202012.member_casual))
正如@Paul 所建议的,您收到此错误是因为 CTE(即 WITH 语句)只是查询的一部分。它后面需要跟另一个语句,通常是 SELECT。您也可以参考此Whosebug question,其中讨论了相同的错误。
您可以试试下面我修改过的代码来解决错误。
WITH analysis_fall_2021_season AS
(SELECT
start_station_name,
end_station_name,
EXTRACT (DATE FROM started_at) AS start_date,
EXTRACT (DATE FROM ended_at) AS end_date,
EXTRACT (TIME FROM started_at) AS start_time,
EXTRACT (TIME FROM ended_at) AS end_time,
DATETIME_DIFF (ended_at,started_at, MINUTE) AS total_lenght,
member_casual
FROM
(SELECT
fall_analysis.ride_id,
fall_analysis.started_at,
fall_analysis.ended_at,
fall_analysis.start_station_name,
fall_analysis.end_station_name,
fall_analysis.member_casual
FROM
`ciclystic.cyclistic_seasonal_analysis.fall_202010` AS fall_analysis
INNER JOIN
`ciclystic.cyclistic_seasonal_analysis.fall_202011` AS fall_202011
ON
fall_analysis.member_casual = fall_202011.member_casual
INNER JOIN
`ciclystic.cyclistic_seasonal_analysis.fall_202012` AS fall_202012
ON
fall_analysis.member_casual = fall_202012.member_casual)
)
SELECT * FROM analysis_fall_2021_season;
我一直在尝试在以下查询中使用 CREATE TEMPORARY TABLE 和 WITH 语句构建临时 Table。到目前为止,我还没有得到任何积极的结果,我也不知道发生了什么。 在最后一行,错误警报显示:“语法错误:应为“(”或“,”或关键字 SELECT,但在 [28:62] 处结束了脚本”
WITH analysis_fall_2021_season AS
(SELECT
start_station_name,
end_station_name,
EXTRACT (DATE FROM started_at) AS start_date,
EXTRACT (DATE FROM ended_at) AS end_date,
EXTRACT (TIME FROM started_at) AS start_time,
EXTRACT (TIME FROM ended_at) AS end_time,
DATETIME_DIFF (ended_at,started_at, MINUTE) AS total_lenght,
member_casual
FROM
(SELECT
fall_analysis.ride_id,
fall_analysis.started_at,
fall_analysis.ended_at,
fall_analysis.start_station_name,
fall_analysis.end_station_name,
fall_analysis.member_casual
FROM
`ciclystic.cyclistic_seasonal_analysis.fall_202010` AS fall_analysis
INNER JOIN
`ciclystic.cyclistic_seasonal_analysis.fall_202011` AS fall_202011
ON
fall_analysis.member_casual = fall_202011.member_casual
INNER JOIN
`ciclystic.cyclistic_seasonal_analysis.fall_202012` AS fall_202012
ON
fall_analysis.member_casual = fall_202012.member_casual))
正如@Paul 所建议的,您收到此错误是因为 CTE(即 WITH 语句)只是查询的一部分。它后面需要跟另一个语句,通常是 SELECT。您也可以参考此Whosebug question,其中讨论了相同的错误。
您可以试试下面我修改过的代码来解决错误。
WITH analysis_fall_2021_season AS
(SELECT
start_station_name,
end_station_name,
EXTRACT (DATE FROM started_at) AS start_date,
EXTRACT (DATE FROM ended_at) AS end_date,
EXTRACT (TIME FROM started_at) AS start_time,
EXTRACT (TIME FROM ended_at) AS end_time,
DATETIME_DIFF (ended_at,started_at, MINUTE) AS total_lenght,
member_casual
FROM
(SELECT
fall_analysis.ride_id,
fall_analysis.started_at,
fall_analysis.ended_at,
fall_analysis.start_station_name,
fall_analysis.end_station_name,
fall_analysis.member_casual
FROM
`ciclystic.cyclistic_seasonal_analysis.fall_202010` AS fall_analysis
INNER JOIN
`ciclystic.cyclistic_seasonal_analysis.fall_202011` AS fall_202011
ON
fall_analysis.member_casual = fall_202011.member_casual
INNER JOIN
`ciclystic.cyclistic_seasonal_analysis.fall_202012` AS fall_202012
ON
fall_analysis.member_casual = fall_202012.member_casual)
)
SELECT * FROM analysis_fall_2021_season;