简体   繁体   English

如何在 bigquery 中动态连接表以避免公共列重复

[英]how to dynamically join tables in bigquery to avoid duplication of common columns

I have 2 tables with a large number of columns (each has around 700-800 columns, which makes it not feasible to individually write all the column names).我有 2 个包含大量列的表(每个表大约有 700-800 列,这使得单独编写所有列名不可行)。 Both the tables have a few common rows.这两个表都有一些共同的行。 I need to dynamically union both the tables such that the common columns don't get repeated and are queried only once in the final table.我需要动态合并这两个表,这样公共列就不会重复,并且在最终表中只被查询一次。 For example:例如:

TABLE 1:
+---------+--------+------+-------+
|firstname|lastname|upload|product|
+---------+--------+------+-------+
|    alice|       a|   100|apple  | 
|      bob|       b|    23|orange |
+---------+--------+------+-------+

TABLE 2:表 2:

+---------+--------+------+-------+
|firstname|lastname|books |active |
+---------+--------+------+-------+
|    alice|       a|   10 |yes    | 
|      bob|       b|    2 |no     |
+---------+--------+------+-------+

FINAL TABLE:决赛桌:

+---------+--------+------+-------+-----+------+
|firstname|lastname|upload|product|books|active|
+---------+--------+------+-------+-----+------+
|    alice|       a|   100|apple  | 10  | yes  |
|      bob|       b|    23|orange | 2   | no   | 
+---------+--------+------+-------+-----+------+

Just to give you a direction to look into只是给你一个方向去研究

select *
from table1
join table2
using(firstname, lastname)          

if applied to sample data in your question - output is如果应用于您问题中的示例数据 - output 是

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM