如何总和每个值和每个阶段
用BigQuery在每个赛季的每个阶段为每个团队增加要点
saison |stage |team_home |team_away|home_goal|away_goal| home_point| away_point|
---------------------------------------------------------------------------------
2002 | 1 |France |Bresil |2 |1 | 3 |0 |
2002 | 1 |Italie |Bresil |4 |3 | 3 |0 |
2002 | 1 |France |Italie |1 |1 | 1 |1 |
2002 | 2 |Italie |Bresil |3 |4 | 0 |3 |
2002 | 2 |France |Italie |1 |1 | 1 |1 |
2002 | 2 |Italie |Bresil |3 |4 | 0 |3 |
2002 | 3 |France |Italie |1 |1 | 1 |1 |
2003 | 1 |Italie |Bresil |3 |4 | 0 |3 |
2003 | 1 |France |Italie |1 |2 | 0 |3 |
2003 | 1 |Bresil |France |0 |1 | 0 |3 |
2003 | 2 |France |Italie |1 |2 | 0 |3 |
2003 | 2 |Bresil |France |0 |1 | 0 |3 |
2003 | 2 |France |Italie |1 |2 | 0 |3 |
2003 | 3 |Italie |France |0 |1 | 0 |3 |
想
saison |stage |team |team_point|
--------------------------------------
2002 | 1 |France |4 |
2002 | 1 |Italie |4 |
2002 | 1 |Bresil |0 |
2002 | 2 |France |5 |
2002 | 2 |Italie |5 |
2002 | 2 |Bresil |3 |
2002 | 3 |France |6 |
2002 | 3 |Italie |6 |
2002 | 3 |Bresil |3 |
2003 | 1 |France |3 |
2003 | 1 |Italie |3 |
2003 | 1 |Bresil |3 |
2003 | 2 |France |6 |
2003 | 2 |Italie |9 |
2003 | 2 |Bresil |3 |
2003 | 3 |France |9 |
2003 | 3 |Italie |9 |
2003 | 3 |Bresil |3 |
对于这张桌子,我
For this table, i want to make addition of the points for each team in each stage of each season with bigquery
saison |stage |team_home |team_away|home_goal|away_goal| home_point| away_point|
---------------------------------------------------------------------------------
2002 | 1 |France |Bresil |2 |1 | 3 |0 |
2002 | 1 |Italie |Bresil |4 |3 | 3 |0 |
2002 | 1 |France |Italie |1 |1 | 1 |1 |
2002 | 2 |Italie |Bresil |3 |4 | 0 |3 |
2002 | 2 |France |Italie |1 |1 | 1 |1 |
2002 | 2 |Italie |Bresil |3 |4 | 0 |3 |
2002 | 3 |France |Italie |1 |1 | 1 |1 |
2003 | 1 |Italie |Bresil |3 |4 | 0 |3 |
2003 | 1 |France |Italie |1 |2 | 0 |3 |
2003 | 1 |Bresil |France |0 |1 | 0 |3 |
2003 | 2 |France |Italie |1 |2 | 0 |3 |
2003 | 2 |Bresil |France |0 |1 | 0 |3 |
2003 | 2 |France |Italie |1 |2 | 0 |3 |
2003 | 3 |Italie |France |0 |1 | 0 |3 |
I want this result :
saison |stage |team |team_point|
--------------------------------------
2002 | 1 |France |4 |
2002 | 1 |Italie |4 |
2002 | 1 |Bresil |0 |
2002 | 2 |France |5 |
2002 | 2 |Italie |5 |
2002 | 2 |Bresil |3 |
2002 | 3 |France |6 |
2002 | 3 |Italie |6 |
2002 | 3 |Bresil |3 |
2003 | 1 |France |3 |
2003 | 1 |Italie |3 |
2003 | 1 |Bresil |3 |
2003 | 2 |France |6 |
2003 | 2 |Italie |9 |
2003 | 2 |Bresil |3 |
2003 | 3 |France |9 |
2003 | 3 |Italie |9 |
2003 | 3 |Bresil |3 |
I think to make unpivot and use an aggregation but i can't do it
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
考虑以下查询:
输出与您的预期略有不同:
多亏了 @saransh的友好解释,除了一件事,输出更接近您的预期输出
(更新)
Consider below query:
output is slightly different from your expected one :
Thanks to @Saransh's kind explanation, output get more close to your expected output
except one thing.(update)
请考虑以下方法
如果应用于问题中的示例数据 - 输出为
Consider below approach
if applied to sample data in your question - output is
如果所有团队都在各个阶段和saisons中同时参加了主场和外摆动,那么您可以创建一个列(team_point),该专栏总结了home_point的添加和由saison,stage and stage and team_home组成的home_point和avey_point(使用Team Away不会有所作为):
如果任何团队只有在任何阶段或赛义德都在家(或离开)的机会,那么您可以首先列出所有不同的球队。
If all teams have played both home and away in all stages and saisons, then you can just create a column (team_point) that sums the addition of home_point and away_point grouped by saison, stage and team_home (using team away wouldn't make a difference):
If there's a chance that any team have only played home (or away) in any stage or saison, then you could list all diferent teams first.
OP您的帖子要求不太清楚,请对其进行更新以反映实际要求。我可以从上面的输出中推断出的是,您需要每个团队的累计总和分别向第2阶段和第3阶段转移到第2阶段。
输出:
OP the requirements of your post are not very clear, please update it to reflect the actual requirements. What I could deduce from the above output is that you require the cumulative sum for each team for each saison to be carry forwarded to the stage 2 and 3 respectively.
Output: