MySQL分组问题
我有一个运动追踪器 MySQL 数据库,正在尝试提取一些统计数据;相关表格概述如下:
游戏
id bigint(20) unsigned PK
round_id bigint(20)
team_1_id bigint(20) 无符号
team_2_id bigint(20) 无符号
日期 日期时间
团队
ID bigint(20) 未签名 PK
name varchar(128)
玩家(此查询并非真正需要)
id bigint(20) unsigned PK
名字 varchar(128)
姓氏 varchar(128)
dob datetime
player_team_game
id bigint(20) 未签名 PK
game_id bigint(20) 无符号
player_id bigint(20) 无符号
team_id bigint(20)
统计信息
id bigint(20) PK
player_team_game_id bigint(20)
踢 int(11)
目标 int(11)
铲断 int(11)
目的是确定每支球队在每场比赛中的总踢球数、进球数和铲断数。示例结果集可能如下所示:
game.id | game.date | team.name | stats.kicks | stats.goals | stats.tackles
1 | 2011-01-01 | team1 | 25 | 30 | 35
1 | 2011-01-01 | team2 | 26 | 31 | 36
2 | 2011-01-01 | team3 | 27 | 32 | 37
2 | 2011-01-01 | team4 | 28 | 33 | 38
3 | 2011-01-02 | team5 | 29 | 34 | 39
3 | 2011-01-02 | team6 | 30 | 35 | 40
任何人都可以帮助我进行适当的查询吗?
编辑:可能我还没有把问题说清楚;问题是游戏表同时具有 game.team_id_1 和 game.team_id_2,因此分组需要在单独的记录集中反映每个团队的结果。
I have a sports tracker MySQL database and am trying to extract some stats; relevant tables are outlined below:
game
id bigint(20) unsigned PK
round_id bigint(20)
team_1_id bigint(20) unsigned
team_2_id bigint(20) unsigned
date datetime
team
id bigint(20) unsigned PK
name varchar(128)
player (not really required for this query)
id bigint(20) unsigned PK
first_name varchar(128)
surname varchar(128)
dob datetime
player_team_game
id bigint(20) unsigned PK
game_id bigint(20) unsigned
player_id bigint(20) unsigned
team_id bigint(20)
stats
id bigint(20) PK
player_team_game_id bigint(20)
kicks int(11)
goals int(11)
tackles int(11)
The intent is to determine total kicks, goals and tackles for each team in each game. An example resultset might look like the following:
game.id | game.date | team.name | stats.kicks | stats.goals | stats.tackles
1 | 2011-01-01 | team1 | 25 | 30 | 35
1 | 2011-01-01 | team2 | 26 | 31 | 36
2 | 2011-01-01 | team3 | 27 | 32 | 37
2 | 2011-01-01 | team4 | 28 | 33 | 38
3 | 2011-01-02 | team5 | 29 | 34 | 39
3 | 2011-01-02 | team6 | 30 | 35 | 40
Can anyone help me with an appropriate query?
Edit: potentially I haven't made the problem clear; the issue is that the game table has both game.team_id_1 and game.team_id_2 so grouping needs to reflect the results for each team in separate recordsets.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
试试这个:
Try this:
我认为下面应该给出您想要的结果。
I would think that the below should give the result that you want.