简体   繁体   English

BigQuery Standard SQL - 查询具有相同架构的 3 个不同表。 如何添加每行来自哪个表的列?

[英]BigQuery Standard SQL - querying 3 different tables with same schema. How to add column with what table each row is from?

Say I have 3 tables containing clothing brands from - walmart, target, amazon.假设我有 3 个表,其中包含来自沃尔玛、塔吉特、亚马逊的服装品牌。 I make a new table and query * from each table into this new table.我创建了一个新表并将每个表中的 * 查询到这个新表中。 I want to know which company (walmart, target or amazon) each of these items is from.我想知道这些商品来自哪家公司(沃尔玛、塔吉特或亚马逊)。 How would I go about doing this in BigQuery?我 go 如何在 BigQuery 中执行此操作?

Thank you.谢谢你。

Use below approach使用以下方法

select *, 'table1' as source from table1 union all
select *, 'table2' from table2 union all
select *, 'table3' from table3

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

相关问题 如何(空间)将许多表连接到另一个 BigQuery 表的每一行? - How to (spatial) JOIN many tables to each row of another BigQuery table? 如何将多个文件(相同模式)从 LOCAL 加载到 BigQuery 中的表中? - How to load multiple files (same schema) from LOCAL into a table in BigQuery? Bigquery 将列添加到表架构 - Bigquery add columns to table schema 如何将 BigQuery 中的列添加到没有架构的表中而不删除它在 SQL 中的当前标签? - How to add columns in BigQuery to a table with no schema without deleting it's current labels in SQL? BigQuery - 将列添加到现有表 - BigQuery - Add column to existing table 如何调用存储在最后一行的值并添加到新列中? 大查询 - SQL - How to call value stored in last row and add into a new column? BigQuery - SQL BigQuery Standard SQL - 加入不同格式的日期 - BigQuery Standard SQL - Join on date with different formats 如何将一个表中的列与 BigQuery 中另一个表中的数组进行比较? - How to compare column in one table with array from another table in BigQuery? 如何合并以临时表逻辑 BigQuery SQL 开头的两个表 - how to union two tables that starts with temporary table logic BigQuery SQL 在bigquery中的同一列上应用不同的条件 - Applying different condition on the same column in bigquery
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM