As @Jon noted, you need to remove those elements that are NOT applicable to a particular person. Then, since @Ord had the closest sample, it would be better to pre-query the results in a separate table (not temporary, since MySQL will strangle it, trying to query itself in a self-join in the second query).
So, for me (being a bowler in a league a few years ago), and your content covering all leagues, at the same time, there will never be two different leagues in the same lane, however, for the whole evening, you could have different leagues starting different times ... 6-8: 30, 8: 45-11, for example ... so grouping by league and date will work. However, you need the player to be part of the group in order to get the corresponding SUM () values.
To help clarify the answers, suppose I have the following data. This data will represent only one streak, one week, one season, but two leagues and 3 players per league (for the sole purpose of showing results and restricting content here).
League Player Score L1 1 223 L1 1 218 L1 1 204 L1 2 187 L1 2 201 L1 2 189 L1 3 148 L1 3 152 L1 3 158 L2 4 189 L2 4 195 L2 4 192 L2 5 182 L2 5 199 L2 5 209 L2 6 228 L2 6 234 L2 6 218 CREATE TABLE SeriesScores2 SELECT Season, LeagueName, LaneNumber, WeekNumber, PlayerID, SUM(Score) AS Series FROM Scores GROUP BY Season, LeagueName, LaneNumber, WeekNumber, PlayerID;
The first request (above) will create will create a series for all players during all weeks, all leagues, etc. Suppose now that I added in the regular season, strip, week too
Season League Lane Week Player Series 1 L1 1 1 1 645 1 L1 1 1 2 577 1 L1 1 1 3 458 1 L2 1 1 4 576 1 L2 1 1 5 590 1 L2 1 1 6 680
This gives us the predecessor of the definition of max (), otherwise we would have to duplicate the request internally and externally, which would complicate this preliminary aggregation.
Now, the above permanent table (can be deleted AFTER you get the results), request FIRST (PreQuery) for the maximum score PER LEAGUE PER LANE ... Ex :, its common that the men's league tends to have higher series scores than women ... similar to different age groups. Therefore, the Men League Lane 1 highest score and the League of Women's League 1 highest score, etc. The highest result is usually determined by one week of the entire season, and not by the highest series per lane every week.
Now the nickname "ss" PreQuery is only in the season, league, lane and maximum series. Once THIS is known, join the series to get WHO, to get the highest score in the indicated band and to get who and what week it came.
select ss.season, ss.leaguename, ss.lanenumber, ss.highestSeries, ss2.PlayerID, ss2.WeekNumber from ( select season, leaguename, lanenumber, max( series ) highestSeries from SeriesScores2 group by season, leaguename, lanenumber ) ss join SeriesScores2 ss2 on ss.Season = ss2.Season and ss.LeagueName = ss2.LeagueName and ss.LaneNumber = ss2.LaneNumber and ss.HighestSeries = ss2.Series
Now from the above request ... let it break. If you take the internal "ss" prequery
( select season, leaguename, lanenumber, max( series ) highestSeries from SeriesScores2 group by season, leaguename, lanenumber ) ss
We will get the highest scores for the league (for example: Men's League vs Women's League in the same week, same night, in the same strip, and we find (below), just max, but we donβt have WHO or in which week, only the highest bowling series, regardless of the week or person, so IT becomes the backbone of JOIN back to the SeriesScores2 pre-aggregated table, but here we have the highest score series to make sure we find the right person
Season League Lane HighestSeries 1 L1 1 645 1 L2 1 680 To refresh preaggregation Season League Lane Week Player Series 1 L1 1 1 1 645 <-- Join finds THIS entry League 1 1 L1 1 1 2 577 1 L1 1 1 3 458 1 L2 1 1 4 576 1 L2 1 1 5 590 1 L2 1 1 6 680 <-- Join finds THIS entry League 2
So, my original queries really worked when I tested them before publishing. I don't know what your hiccup was if the column name is not correct or something like that. As with the Date column, I was not interested because you had an available number of weeks that would correspond to a bowling week and in any case be a 1: 1 ratio to date. A date column could be added to SeriesScores2 pre-aggregation and pulled together when the person identifier and week are obtained. (if the league is not many times a week, THEN you will need an explicit date).
We hope this clarifies your questions / comments.