在 BigQuery SQL 查询的数据集中创建永久 table 的语法是什么?
What is the syntax for creating a permanent table within the dataset in a BigQuery SQL query?
问题总结:
我有一个临时的 table 作为我查询的结果,以便通过使用 WITH 语句合并 12 个月的数据。我可以保存温度。 table 通过将视图保存为永久视图手动 table 然后我将其导出以在我的可视化应用程序中使用。
我想知道添加到我的查询中的适当语法,以便该过程 运行 无缝。
描述您尝试过的内容:
我尝试使用 CREATE TABLE、EXECUTE IMMEDIATE(concat...等),但出现错误。
在适当的时候,显示一些代码:
能否请您与我分享可能的正确代码以添加到我的以下查询中(我缩短了代码)
temptable 作为我的临时 table。
说 permtable 是我的永久 table as project.data_set.permtable
谢谢。
WITH
temptable AS (
#May 2021
SELECT
ride_id,
rideable_type,
CAST(started_at AS TIMESTAMP ) AS started_at,
CAST(ended_at AS TIMESTAMP ) AS ended_at,
start_station_name,
CAST(start_station_id AS STRING ) AS start_station_id,
end_station_name,
CAST(end_station_id AS STRING ) AS end_station_id,
start_lat,
start_lng,
end_lat,
end_lng,
member_casual,
timestamp_diff (ended_at,started_at, minute) AS trip_duration,
EXTRACT(DAYOFWEEK FROM started_at) AS day_of_week
FROM
`project.data_set.table1`
UNION ALL
#June 2021
SELECT
ride_id,
rideable_type,
CAST(started_at AS TIMESTAMP ) AS started_at,
CAST(ended_at AS TIMESTAMP ) AS ended_at,
start_station_name,
CAST(start_station_id AS STRING ) AS start_station_id,
end_station_name,
CAST(end_station_id AS STRING ) AS end_station_id,
start_lat,
start_lng,
end_lat,
end_lng,
member_casual,
timestamp_diff (ended_at,started_at, minute) AS trip_duration,
EXTRACT(DAYOFWEEK FROM started_at) AS day_of_week
FROM
`project.data_set.table2` )
SELECT * FROM combined_rides
WHERE
NOT( start_station_id IS NULL
OR end_station_id IS NULL
OR start_lat IS NULL
OR end_lat IS NULL
OR start_station_name LIKE '%CHECKING%'
OR end_station_name LIKE '%CHECKING%'
OR trip_duration < 1 )
您可以使用 CREATE TABLE 语句来实现:
CREATE TABLE IF NOT EXISTS project.data_set.permtable
AS
WITH temptable AS (
#May 2021
SELECT
ride_id,
rideable_type,
CAST(started_at AS TIMESTAMP ) AS started_at,
CAST(ended_at AS TIMESTAMP ) AS ended_at,
start_station_name,
CAST(start_station_id AS STRING ) AS start_station_id,
end_station_name,
CAST(end_station_id AS STRING ) AS end_station_id,
start_lat,
start_lng,
end_lat,
end_lng,
member_casual,
timestamp_diff (ended_at,started_at, minute) AS trip_duration,
EXTRACT(DAYOFWEEK FROM started_at) AS day_of_week
FROM
`project.data_set.table1`
UNION ALL
#June 2021
SELECT
ride_id,
rideable_type,
CAST(started_at AS TIMESTAMP ) AS started_at,
CAST(ended_at AS TIMESTAMP ) AS ended_at,
start_station_name,
CAST(start_station_id AS STRING ) AS start_station_id,
end_station_name,
CAST(end_station_id AS STRING ) AS end_station_id,
start_lat,
start_lng,
end_lat,
end_lng,
member_casual,
timestamp_diff (ended_at,started_at, minute) AS trip_duration,
EXTRACT(DAYOFWEEK FROM started_at) AS day_of_week
FROM
`project.data_set.table2` )
SELECT * FROM combined_rides
WHERE
NOT( start_station_id IS NULL
OR end_station_id IS NULL
OR start_lat IS NULL
OR end_lat IS NULL
OR start_station_name LIKE '%CHECKING%'
OR end_station_name LIKE '%CHECKING%'
OR trip_duration < 1 );
好了,您现在将在指定的项目和数据集中有一个 permtable
table!
问题总结:
我有一个临时的 table 作为我查询的结果,以便通过使用 WITH 语句合并 12 个月的数据。我可以保存温度。 table 通过将视图保存为永久视图手动 table 然后我将其导出以在我的可视化应用程序中使用。
我想知道添加到我的查询中的适当语法,以便该过程 运行 无缝。
描述您尝试过的内容:
我尝试使用 CREATE TABLE、EXECUTE IMMEDIATE(concat...等),但出现错误。
在适当的时候,显示一些代码:
能否请您与我分享可能的正确代码以添加到我的以下查询中(我缩短了代码)
temptable 作为我的临时 table。
说 permtable 是我的永久 table as project.data_set.permtable
谢谢。
WITH
temptable AS (
#May 2021
SELECT
ride_id,
rideable_type,
CAST(started_at AS TIMESTAMP ) AS started_at,
CAST(ended_at AS TIMESTAMP ) AS ended_at,
start_station_name,
CAST(start_station_id AS STRING ) AS start_station_id,
end_station_name,
CAST(end_station_id AS STRING ) AS end_station_id,
start_lat,
start_lng,
end_lat,
end_lng,
member_casual,
timestamp_diff (ended_at,started_at, minute) AS trip_duration,
EXTRACT(DAYOFWEEK FROM started_at) AS day_of_week
FROM
`project.data_set.table1`
UNION ALL
#June 2021
SELECT
ride_id,
rideable_type,
CAST(started_at AS TIMESTAMP ) AS started_at,
CAST(ended_at AS TIMESTAMP ) AS ended_at,
start_station_name,
CAST(start_station_id AS STRING ) AS start_station_id,
end_station_name,
CAST(end_station_id AS STRING ) AS end_station_id,
start_lat,
start_lng,
end_lat,
end_lng,
member_casual,
timestamp_diff (ended_at,started_at, minute) AS trip_duration,
EXTRACT(DAYOFWEEK FROM started_at) AS day_of_week
FROM
`project.data_set.table2` )
SELECT * FROM combined_rides
WHERE
NOT( start_station_id IS NULL
OR end_station_id IS NULL
OR start_lat IS NULL
OR end_lat IS NULL
OR start_station_name LIKE '%CHECKING%'
OR end_station_name LIKE '%CHECKING%'
OR trip_duration < 1 )
您可以使用 CREATE TABLE 语句来实现:
CREATE TABLE IF NOT EXISTS project.data_set.permtable
AS
WITH temptable AS (
#May 2021
SELECT
ride_id,
rideable_type,
CAST(started_at AS TIMESTAMP ) AS started_at,
CAST(ended_at AS TIMESTAMP ) AS ended_at,
start_station_name,
CAST(start_station_id AS STRING ) AS start_station_id,
end_station_name,
CAST(end_station_id AS STRING ) AS end_station_id,
start_lat,
start_lng,
end_lat,
end_lng,
member_casual,
timestamp_diff (ended_at,started_at, minute) AS trip_duration,
EXTRACT(DAYOFWEEK FROM started_at) AS day_of_week
FROM
`project.data_set.table1`
UNION ALL
#June 2021
SELECT
ride_id,
rideable_type,
CAST(started_at AS TIMESTAMP ) AS started_at,
CAST(ended_at AS TIMESTAMP ) AS ended_at,
start_station_name,
CAST(start_station_id AS STRING ) AS start_station_id,
end_station_name,
CAST(end_station_id AS STRING ) AS end_station_id,
start_lat,
start_lng,
end_lat,
end_lng,
member_casual,
timestamp_diff (ended_at,started_at, minute) AS trip_duration,
EXTRACT(DAYOFWEEK FROM started_at) AS day_of_week
FROM
`project.data_set.table2` )
SELECT * FROM combined_rides
WHERE
NOT( start_station_id IS NULL
OR end_station_id IS NULL
OR start_lat IS NULL
OR end_lat IS NULL
OR start_station_name LIKE '%CHECKING%'
OR end_station_name LIKE '%CHECKING%'
OR trip_duration < 1 );
好了,您现在将在指定的项目和数据集中有一个 permtable
table!