有没有一种方法可以连接sql上的两个查询(bigquery)

xzv2uavs  于 2021-07-24  发布在  Java
关注(0)|答案(1)|浏览(310)

我想连接bigquery上的两个查询a和b。
查询a

SELECT membership_no, first_name, surname 
FROM `some.Table1`

查询b

SELECT membership_no, membership_class, membership_status, join_date
FROM `some.Table2`
WHERE join_date BETWEEN '2019-01-01' AND '2019-12-31'
AND membership_status = 'ACTIVE'

有没有一种简洁而优雅的方式连接两个现有的查询?一个亲戚。。。

SELECT *
FROM (A)
JOIN
(B)
USING (membership_no)

不用为a和b写代码?

pnwntuvh

pnwntuvh1#


# standardSQL

WITH queryA AS (
  SELECT membership_no, first_name, surname 
  FROM `some.Table1`
), queryB AS (
  SELECT membership_no, membership_class, membership_status, join_date
  FROM `some.Table2`
  WHERE join_date BETWEEN '2019-01-01' AND '2019-12-31'
AND membership_status = 'ACTIVE'
)
SELECT *
FROM queryA
JOIN queryB
USING (membership_no)

相关问题