0
SQL 지식을 넘어 데이터베이스를 정규화했다고 생각합니다. :) 다음은 스누커 리그 웹 앱에서 고민하고있는 질문입니다. 그것은 모든 계절의 팀에 대한 높은 휴식 시간에 대한 전반적인 통계를 계산합니다. 예제 팀 ID 3.MySQL 지식을 넘어서 표준화 되었습니까?
select max(break_score) maxBreak,avg(break_score) avgBreak, count(break_score) breaks from breaks join matches on match_id=break_match where break_player in ( select distinct player_id from players join team_members on player=player_id and team=3) and (match_hometeam=3 or match_awayteam=3)
테이블 :
- 경기 :
match_id int(11) auto_increment match_hometeam int(11) match_awayteam int(11) match_date date match_void tinyint(4) match_status tinyint(4) match_homescore tinyint(4) match_awayscore tinyint(4) match_league int(11)
- 휴식 :
break_id int(11) auto_increment break_match int(11) foreign key to match_id break_player int(11) break_score tinyint(4) break_clearance tinyint(4) break_year int(11)
- team_members : many to many 테이블.
team int(11) foreign key to teams table player int(11) foreign key to players table year int(11) the year that the player played for the team
한 가지 문제에서 떨어져 의도 한대로 쿼리 위에서 거의 작동합니다. 플레이어가 둘 이상의 팀을 위해 경기를했다면, 모든 팀을위한 휴식 시간이이 통계에 포함됩니다.
브레이크 테이블에 'break_team'이라는 추가 필드가있는 경우 쿼리가 간단합니다. 그래서 내 질문은 두 배입니다. 누구든지 올바른 쿼리를 지원할 수 있습니까? 아니면이 통계를 돕기 위해 정규화를 약간 줄여야합니까? 표준화를 해제 할 때가 언제입니까?
외모 네가 고쳐 준 것처럼. 조회는 마지막 열에서 345를 수집하며, 이는 별도의 모든 시즌 합계의 합계입니다. 내 쿼리는 347을 반환, 다른 시즌과 팀에서 두 휴식. 고마워. – PaulBM
문제가 없으니 다행입니다. 미래의 결함에 대한 답변을 찾으면 다시 확인하겠습니다. –