BigQuery/SQL-特定变体的拆分值 [英] BigQuery/SQL - Split value on specific variants

查看:66
本文介绍了BigQuery/SQL-特定变体的拆分值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

需要将market_offers列中的重复项替换为可以为所有提供主要价值的条目加总的值.但是有时会出现等级和国家/地区代码不同的情况

need to replace duplicates in column market_offers with value that can be SUM for all entries that give main value. but there is a case that there are different rank and country codes so

输入

country_code    rank    store_id    category_id offers  market_offers
se              1       14582       1106        410     504860
se              1       1955        1294        2       504860
se              1       9831        1158        151     504860
se              2       666         11158       536     4000
se              2       6587        25863       6586    4000
se              2       6666        158         536     4000
se              5       65853       76722       1521    302
se              5       6587        25863       6586    302

预期结果

country_code    rank    store_id    category_id offers  market_offers
se              1       14582       1106        410     168 286
se              1       1955        1294        2       168 286
se              1       9831        1158        151     168 286
se              2       666         11158       536     1333
se              2       6587        25863       6586    1333
se              2       6666        158         536     1333
se              5       65853       76722       1521    151
se              5       6587        25863       6586    151

推荐答案

在下面考虑

select * except(market_offers), 
  round(market_offers / count(1) over(partition by market_offers, rank), 2) as market_offers
from `project.dataset.table`               

如果应用于您问题中的样本数据-输出为

if applied to sample data in your question - output is

这篇关于BigQuery/SQL-特定变体的拆分值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆