在SQL查询中双重选择

时间:2016-11-16 01:08:35

标签: sql google-bigquery

在大查询中编写带有两个select语句的代码。不知道为什么它不承认这些领域。找不到错误Field --> 'd3.fiscal_week_begin_date';你的意思是'fiscal_week_begin_date'

SELECT
  *
FROM
  [acquisition.acquisition_program_cost_summary] as test,
  (
  SELECT
    d.fiscal_week_begin_date AS fiscal_week_begin_date,
    d.fiscal_week_end_date AS fiscal_week_end_date
  FROM
    datamart.date_dim as d
  WHERE
    d.week_of_fiscal_year =30) as d3
WHERE
  test.created_timestamp >= d3.fiscal_week_begin_date
  AND test.created_timestamp <= d3.fiscal_week_end_date;

1 个答案:

答案 0 :(得分:2)

在BigQuery中,逗号(,)不代表JOIN,而是代表UNION ALL 所以,很可能你打算像下面这样做JOIN 请注意,您应切换到BigQuery Standard SQL

SELECT *
FROM acquisition.acquisition_program_cost_summary as test
JOIN (
  SELECT
    d.fiscal_week_begin_date AS fiscal_week_begin_date,
    d.fiscal_week_end_date AS fiscal_week_end_date
  FROM datamart.date_dim as d
  WHERE d.week_of_fiscal_year = 30
) as d3
ON test.created_timestamp >= d3.fiscal_week_begin_date
AND test.created_timestamp <= d3.fiscal_week_end_date