MySql中不使用日期的10周期移动平均线
我有一个守门员数据表,下面的片段
year gameid player sv% gamenum
2009 200165 John Smith 0.923 0165
2009 209754 John Smith 1.000 9754
2009 206938 John Smith 1.000 6938
2009 206155 John Smith 0.833 6155
2009 203021 John Smith 0.667 3021
2009 206472 John Smith 0.909 6472
2009 209524 John Smith 0.833 9524
2009 209351 John Smith 0.800 9351
2009 203056 John Smith 1.000 3056
2009 206761 John Smith 0.935 6761
2009 200466 John Smith 0.954 0466
2009 204171 John Smith 0.932 4171
2009 207876 John Smith 0.958 7876
2009 201581 John Smith 0.941 1581
2009 205286 John Smith 0.930 5286
2009 208991 John Smith 0.961 8991
2009 202696 John Smith 0.916 2696
2009 206401 John Smith 0.935 6401
2009 200106 John Smith 0.921 0106
2009 201381 John Smith 0.918 1381
我想获取每个守门员的 10 场比赛移动平均值,但我没有日期或比赛编号,例如他的第一场、第二场、第三场比赛等。游戏 ID 也是按照联赛级别的比赛顺序进行分配,因此 200106 场比赛可能是他本赛季的第一场比赛,200165 可能是他的第二场比赛,依此类推。
我的问题是:如何获得每年每个守门员分组的最大值(10 场比赛移动平均值)和最小值(10 场比赛移动平均值)?
另外,有没有办法使用 MySql 按守门员、年份对游戏 ID 进行排名?
I have a table of goalie data, snipet below
year gameid player sv% gamenum
2009 200165 John Smith 0.923 0165
2009 209754 John Smith 1.000 9754
2009 206938 John Smith 1.000 6938
2009 206155 John Smith 0.833 6155
2009 203021 John Smith 0.667 3021
2009 206472 John Smith 0.909 6472
2009 209524 John Smith 0.833 9524
2009 209351 John Smith 0.800 9351
2009 203056 John Smith 1.000 3056
2009 206761 John Smith 0.935 6761
2009 200466 John Smith 0.954 0466
2009 204171 John Smith 0.932 4171
2009 207876 John Smith 0.958 7876
2009 201581 John Smith 0.941 1581
2009 205286 John Smith 0.930 5286
2009 208991 John Smith 0.961 8991
2009 202696 John Smith 0.916 2696
2009 206401 John Smith 0.935 6401
2009 200106 John Smith 0.921 0106
2009 201381 John Smith 0.918 1381
I want to get the 10 game moving averages for each goalie, but I don't have dates or game numbers such as his first, second, third game, etc. The game ids are also assigned in the order they are played at the league level, so game 200106 could be his first game of season, and 200165 could be his 2nd, and so on.
My question is: How can I get the max(10 game moving average) and min(10 game moving average) grouped by each goalie for each year?
Also, is there a way to rank the game ids by goalie, year using MySql?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
10 场比赛移动平均值意味着如果您的比赛场数少于 10 场,则没有有意义的平均值(比赛次数不足)。如果您有 12 场比赛,则在 12 场比赛之间取平均值。
在 MySQL 中执行此操作的最有效方法是:
这将仅传递数据一次,构建平均值。外部查询将简单地从此派生表中获取最小值/最大值。不过,我现在还不想充实这一点。
A 10 game moving average means that if you had less than 10 games, there is no meaningful average (not enough games). If you had 12 games, the average is taken between
The most efficient way to do this in MySQL would be to
This will pass through the data only once, building the averages. An outer query will simply take min/max from this derived table. I'm not up for fleshing this out at the moment though.
这是一个想法(公平警告:未经测试)
或
This is one idea (fair warning:not tested)
or