bigquery连接中的疑似别名问题

时间:2018-12-19 08:09:24

标签: join google-bigquery alias

我对bigquery相对较新,认为我有一个别名问题,但无法弄清楚它是什么。本质上,我有两个表,而第一个表具有所需的大多数信息,第二个表具有我需要加入的生日。我已经编写了以下查询,并且两个初始的SELECT语句独立工作,并且似乎返回了期望的值。但是,当尝试连接两个表时,出现错误提示:

  

无法识别的名字:t1_teams at [10:60]

WITH table_1 AS (SELECT competition_name, stat_season_name, 
matchdata_Date, t1_teams.name, t1_players.Position, CAST(REGEXP_REPLACE(t1_players.uID, r'[a-zA-Z]', '') AS NUMERIC) AS Player_ID1, t1_players.First, t1_players.Last

FROM `prod.feed1`, 
UNNEST(teams) AS t1_teams, UNNEST(t1_teams.Players) as t1_players),

table_2 AS (SELECT t2_players.uID AS Player_ID2, t2_players.stat_birth_date
FROM `prod.feed2`,
UNNEST(players) AS t2_players)

SELECT competition_name, stat_season_name, matchdata_Date, t1_teams.name, t1_players.Position, t1_players.uID, t1_players.First, t1_players.Last, t2_players.stat_birth_date

FROM table_1
LEFT JOIN table_2
ON Player_ID1 = Player_ID2
WHERE competition_name  = "EPL"
AND stat_season_name = "Season 2018/2019"

由于我对bigquery文档的阅读和其他搜索已为人们留下空白,对指导我朝正确方向提供的任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:0)

问题在这里:

WITH table_1 AS (
  SELECT
    competition_name,
    stat_season_name, 
    matchdata_Date,
    -- this line
    t1_teams.name,
    ...

您要选择t1_teams.name,所以最后只剩下name和选择列表中的输出列。如果以后要引用t1_teams,请改为选择它:

WITH table_1 AS (
  SELECT
    competition_name,
    stat_season_name, 
    matchdata_Date,
    -- this line
    t1_teams,
    ...