简体   繁体   English

我想填充 BigQuery 表数据中有漏洞的行

[英]I want to fill in rows with holes in BigQuery table data

What we want to solve我们要解决的问题

We have never worked much with DWH or sql and don't know how to do it... Can someone please help us?我们从来没有与 DWH 或 sql 合作过,也不知道该怎么做......有人可以帮助我们吗?

We want to fill in the missing rows in the BigQuery table data.我们想要填充 BigQuery 表数据中缺失的行。

Current situation: I have written daily business data in BigQuery like the following master data.目前情况:我每天的业务数据都写在BigQuery里面,像下面这样的主数据。 I would like to overwrite the blank rows in the "male" column, but I don't know what is the best way to do it.我想覆盖“男性”列中的空白行,但我不知道最好的方法是什么。

The table is about 20000 rows.该表大约有 20000 行。

I have a separate table for employee rosters that is linked to the table I want to rewrite by id, so I thought it would be better to use that, but I am having trouble getting to it...我有一个单独的员工名册表,该表链接到我想通过 id 重写的表,所以我认为使用它会更好,但我很难找到它......

Problem/error问题/错误

-Master data
date       id   name gender task
2022-08-01 0001 Jack        projectA
2022-08-02 0001 Jack  male  projectA
2022-08-03 0001 Jack        projectA
2022-08-04 0001 Jack  male  projectB
2022-08-05 0001 Jack        projectB
2022-08-01 0002 Smith male  projectA
2022-08-02 0003 Smith       projectB
2022-08-03 0004 Smith male  projectB
-Employee Roster Table
id   name     gender 
0001 Jack     male
0002 Smith    male
0003 Paul     male
0004 Naomi    Female

Translated with www.DeepL.com/Translator (free version)www.DeepL.com/Translator翻译(免费版)

Assuming IDs in the employee roster table are unique, you can use a JOIN operation假设员工花名册表中的 ID 是唯一的,您可以使用JOIN 操作

If you want to overwrite the gender column altogether with the roster data the query would look something like如果你想用名册数据完全覆盖性别列,查询看起来像

select
  main.date,
  main.id,
  main.name
  roster.gender
  main.task
from main_table as main
left join employee_roster_table as roster on main.id = roster.id

If you want to keep the gender that are filled in the main table and only use the roster's when null you can use如果你想保留主表中填写的性别,并且只在null时使用花名册,你可以使用

select
  main.date,
  main.id,
  main.name
  coalesce(main.gender, roster.gender) as gender
  main.task
from main_table as main
left join employee_roster_table as roster on main.id = roster.id

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

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