Welcome to Subscribe On Youtube
1308. Running Total for Different Genders
Description
Table: Scores
+++  Column Name  Type  +++  player_name  varchar   gender  varchar   day  date   score_points  int  +++ (gender, day) is the primary key (combination of columns with unique values) for this table. A competition is held between the female team and the male team. Each row of this table indicates that a player_name and with gender has scored score_point in someday. Gender is 'F' if the player is in the female team and 'M' if the player is in the male team.
Write a solution to find the total score for each gender on each day.
Return the result table ordered by gender
and day
in ascending order.
The result format is in the following example.
Example 1:
Input: Scores table: +++++  player_name  gender  day  score_points  +++++  Aron  F  20200101  17   Alice  F  20200107  23   Bajrang  M  20200107  7   Khali  M  20191225  11   Slaman  M  20191230  13   Joe  M  20191231  3   Jose  M  20191218  2   Priya  F  20191231  23   Priyanka  F  20191230  17  +++++ Output: ++++  gender  day  total  ++++  F  20191230  17   F  20191231  40   F  20200101  57   F  20200107  80   M  20191218  2   M  20191225  13   M  20191230  26   M  20191231  29   M  20200107  36  ++++ Explanation: For the female team: The first day is 20191230, Priyanka scored 17 points and the total score for the team is 17. The second day is 20191231, Priya scored 23 points and the total score for the team is 40. The third day is 20200101, Aron scored 17 points and the total score for the team is 57. The fourth day is 20200107, Alice scored 23 points and the total score for the team is 80. For the male team: The first day is 20191218, Jose scored 2 points and the total score for the team is 2. The second day is 20191225, Khali scored 11 points and the total score for the team is 13. The third day is 20191230, Slaman scored 13 points and the total score for the team is 26. The fourth day is 20191231, Joe scored 3 points and the total score for the team is 29. The fifth day is 20200107, Bajrang scored 7 points and the total score for the team is 36.
Solutions

# Write your MySQL query statement below SELECT gender, day, SUM(score_points) OVER ( PARTITION BY gender ORDER BY gender, day ) AS total FROM Scores;