将9个表迁移到一个BigQuery中

时间:2016-05-06 13:35:07

标签: sql join google-bigquery

我正在尝试将8个表中的数据复制到BigQuery中的一个空表中。 我希望将我从第一家公司的成本转移到all_costs。我试过插入并发现它没有得到支持,我很乐意在这里得到一些帮助。 all_costs是一个空表,包含以下字段,与每个其他表相同 它还需要创建一个新列,说明公司名称

Date    Country Operation system    Costs type  costs
Yyyy-dd-mm  At  And a   12
Yyyy-dd-mm  at  And b   324.245
SELECT *
FROM  [Costs.all_costs] A
JOIN EACH [Costs.first_company] B 
ON (B.date < '05-06-2015') AND (A.date is NULL)

1 个答案:

答案 0 :(得分:1)

下面简单的代码应该适合你

SELECT * FROM
  (SELECT 'company_1' AS company, * FROM  [Costs.company_1]), 
  (SELECT 'company_2' AS company, * FROM  [Costs.company_2]), 
  (SELECT 'company_3' AS company, * FROM  [Costs.company_3]), 
  (SELECT 'company_4' AS company, * FROM  [Costs.company_4]), 
  (SELECT 'company_5' AS company, * FROM  [Costs.company_5]), 
  (SELECT 'company_6' AS company, * FROM  [Costs.company_6]), 
  (SELECT 'company_7' AS company, * FROM  [Costs.company_7]), 
  (SELECT 'company_8' AS company, * FROM  [Costs.company_8])

确保在UI中设置目的地表和写入首选项(在显示选项按钮下)