简体   繁体   English

在 BigQuery 中,如何汇总匹配相同日期和 ID 的字段?

[英]In BigQuery how do I total fields that match the same date and id?

I have some data in BigQuery that is 3 columns: date, id, quantity.我在 BigQuery 中有一些数据是 3 列:日期、ID、数量。 Example:例子:

2021-2-2 | abcd | 123
2021-2-2 | abcd | 456
2021-2-1 | efgh | 321
2021-2-1 | efgh | 654

I'd like to combine and total where the dates and ids match like so:我想组合和总计日期和 id 匹配的位置,如下所示:

2021-2-2 | abcd | 579
2021-2-1 | efgh | 975

I think the best way to go about this would be to put all of the new data into a new BigQuery table, then delete the old.我认为 go 的最佳方法是将所有新数据放入一个新的 BigQuery 表中,然后删除旧的。 How would I go about running the query and writing to a new table for a large data set using a Node Cloud Function?我将如何 go 使用节点云 Function 运行查询并写入大型数据集的新表?

If I understand correctly, you just want group by :如果我理解正确,您只需要group by

select date, id, sum(quantity)
from t
group by date, id;

If this answers your question, you should make some effort to learn SQL -- there are many tutorials, books, and online resources that can help.如果这回答了您的问题,您应该努力学习 SQL - 有许多教程、书籍和在线资源可以提供帮助。 GROUP BY is very basic SQL and some background in the language will help you use BigQuery. GROUP BY是非常基本的 SQL,一些语言背景将帮助您使用 BigQuery。

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

相关问题 如何在 BigQuery 中随机匹配元素 - How Do I Randomly Match Elements in BigQuery Bigquery - 如何选择where子句中的字段而不是常量? - Bigquery - how do i select the fields that are in my where clause and not constants? 如何 select 匹配行并在同一张表上匹配其 ID 和 Date - how to select matching row and match its ID and Date on the same table 如何在bigquery中将字符串yyyy / mm / dd转换为日期? - How do I convert a string yyyy/mm/dd to date in bigquery? 如何在 BigQuery 中将 GPS 时间转换为日期 - How do I convert gps time to date in BigQuery 如何在 bigquery 中插入一行 DATE 类型的列 - How do I insert a row in bigquery with a column of type DATE PHP:如何对表中的总共3个字段进行ORDER BY? - PHP: How do I ORDER BY total of 3 fields in Table? 在MySQL中,我如何更新一批字段以将它们的值与对应于同一表中的entity_id的值连接起来? - In MySQL how do I update a batch of fields to concatenate their values with those that correspond to the entity_id in the same table? 在 Bigquery 中计算每天总记录数和每天具有相同时间时间戳和 id 的总记录数的查询 - Query that counts total records per day and total records with same time timestamp and id per day in Bigquery Google Bigquery:如何在同一列中划分2个值? - Google Bigquery: How do I divide 2 values in the same column?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM