in bigquery的sql多重查询

i2loujxw  于 2021-08-13  发布在  Java
关注(0)|答案(1)|浏览(413)

我试图弄清楚如何发出一个包含多个查询的请求,以便生成一个包含所有查询结果的视图。
举个例子:

WITH Query_1 AS
(
SELECT
dimension1,
dimension2,
dimension3,
dimension4,
dimension5,

CASE WHEN STARTS_WITH (dimension1, "N_") THEN '1' ELSE '0' END AS qadimension1,
CASE WHEN dimension2 IS NOT NULL THEN dimension2 ELSE '0' END AS qadimension2,
CASE WHEN dimension3 IS NOT NULL THEN dimension3 ELSE '0' END AS qadimension3,
CASE WHEN dimension4 IS NOT NULL THEN dimension4 ELSE '0' END AS qadimension4,
FROM `XXXXX.XXXXX.first_view`
WHERE dimension5='2021' AND dimension1 IS NOT NULL),

Query_2 AS (
SELECT
dimension1,
qadimension1,
dimension6,

CASE WHEN qadimension1 = dimension6 THEN '1' ELSE '0' END AS QA_check1,
FROM `XXXXX.XXXXX.first_view` , `XXXXX.XXXXX.second_view`
WHERE qadimension1 != '0'),

Query_3 AS (
SELECT
dimension1,
qadimension2,
dimension7,

CASE WHEN qadimension2 = dimension7 THEN '1' ELSE '0' END AS QA_check2,
FROM `XXXXX.XXXXX.first_view` , `XXXXX.XXXXX.third_view`
WHERE qadimension2 != '0')

SELECT 
dimension1,
dimension2,
dimension3,
dimension4,
dimension5,
dimension6,
dimension7,

qadimension1,
qadimension2,
qadimension3,
qadimension4,

QA_check1,
QA_check2,

FROM
Query_1,
Query_2,
Query_3

WHERE FULL JOIN dimension1;

仍有错误:语法错误:在[242:7]处出现意外的关键字full
非常感谢你的帮助

ejk8hzay

ejk8hzay1#

下面是bigquery标准sql
尝试下面-注意所有CTE没有变化,所以下面只是最后的select语句

SELECT 
  dimension1,
  dimension2,
  dimension3,
  dimension4,
  dimension5,
  dimension6,
  dimension7,

  q2.qadimension1,
  q3.qadimension2,
  qadimension3,
  qadimension4,

  QA_check1,
  QA_check2

FROM Query_1
LEFT JOIN Query_2 q2 USING(dimension1)
LEFT JOIN Query_3 q3 USING(dimension1)

相关问题