Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 3a25e14

Browse files
add 1308
1 parent 01ddad4 commit 3a25e14

File tree

2 files changed

+70
-0
lines changed

2 files changed

+70
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -882,6 +882,7 @@ _If you like this project, please leave me a star._ ★
882882
|1341|[Movie Rating](https://leetcode.com/problems/movie-rating/)|[Solution](../master/database/_1341.sql) || Medium |
883883
|1327|[List the Products Ordered in a Period](https://leetcode.com/problems/list-the-products-ordered-in-a-period/)|[Solution](../master/database/_1327.sql) || Easy |
884884
|1322|[Ads Performance](https://leetcode.com/problems/ads-performance/)|[Solution](../master/database/_1322.sql) || Easy |
885+
|1308|[Running Total for Different Genders](https://leetcode.com/problems/running-total-for-different-genders/)|[Solution](../master/database/_1308.sql) || Medium |
885886
|1294|[Weather Type in Each Country](https://leetcode.com/problems/weather-type-in-each-country/)|[Solution](../master/database/_1294.sql) | | Easy |
886887
|1280|[Students and Examinations](https://leetcode.com/problems/students-and-examinations/)|[Solution](../master/database/_1280.sql) | [:tv:](https://www.youtube.com/watch?v=ThbkV4Fs7iE)| Easy |
887888
|1251|[Average Selling Price](https://leetcode.com/problems/average-selling-price/)|[Solution](../master/database/_1251.sql) | | Easy |

database/_1308.sql

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
--1308. Running Total for Different Genders
2+
--
3+
--Table: Scores
4+
--
5+
--+---------------+---------+
6+
--| Column Name | Type |
7+
--+---------------+---------+
8+
--| player_name | varchar |
9+
--| gender | varchar |
10+
--| day | date |
11+
--| score_points | int |
12+
--+---------------+---------+
13+
--(gender, day) is the primary key for this table.
14+
--A competition is held between females team and males team.
15+
--Each row of this table indicates that a player_name and with gender has scored score_point in someday.
16+
--Gender is 'F' if the player is in females team and 'M' if the player is in males team.
17+
--
18+
--
19+
--Write an SQL query to find the total score for each gender at each day.
20+
--
21+
--Order the result table by gender and day
22+
--
23+
--The query result format is in the following example:
24+
--
25+
--Scores table:
26+
--+-------------+--------+------------+--------------+
27+
--| player_name | gender | day | score_points |
28+
--+-------------+--------+------------+--------------+
29+
--| Aron | F | 2020-01-01 | 17 |
30+
--| Alice | F | 2020-01-07 | 23 |
31+
--| Bajrang | M | 2020-01-07 | 7 |
32+
--| Khali | M | 2019-12-25 | 11 |
33+
--| Slaman | M | 2019-12-30 | 13 |
34+
--| Joe | M | 2019-12-31 | 3 |
35+
--| Jose | M | 2019-12-18 | 2 |
36+
--| Priya | F | 2019-12-31 | 23 |
37+
--| Priyanka | F | 2019-12-30 | 17 |
38+
--+-------------+--------+------------+--------------+
39+
--Result table:
40+
--+--------+------------+-------+
41+
--| gender | day | total |
42+
--+--------+------------+-------+
43+
--| F | 2019-12-30 | 17 |
44+
--| F | 2019-12-31 | 40 |
45+
--| F | 2020-01-01 | 57 |
46+
--| F | 2020-01-07 | 80 |
47+
--| M | 2019-12-18 | 2 |
48+
--| M | 2019-12-25 | 13 |
49+
--| M | 2019-12-30 | 26 |
50+
--| M | 2019-12-31 | 29 |
51+
--| M | 2020-01-07 | 36 |
52+
--+--------+------------+-------+
53+
--For females team:
54+
--First day is 2019-12-30, Priyanka scored 17 points and the total score for the team is 17.
55+
--Second day is 2019-12-31, Priya scored 23 points and the total score for the team is 40.
56+
--Third day is 2020-01-01, Aron scored 17 points and the total score for the team is 57.
57+
--Fourth day is 2020-01-07, Alice scored 23 points and the total score for the team is 80.
58+
--For males team:
59+
--First day is 2019-12-18, Jose scored 2 points and the total score for the team is 2.
60+
--Second day is 2019-12-25, Khali scored 11 points and the total score for the team is 13.
61+
--Third day is 2019-12-30, Slaman scored 13 points and the total score for the team is 26.
62+
--Fourth day is 2019-12-31, Joe scored 3 points and the total score for the team is 29.
63+
--Fifth day is 2020-01-07, Bajrang scored 7 points and the total score for the team is 36.
64+
65+
--# Write your MySQL query statement below
66+
select s1.gender, s1.day, sum(s2.score_points) as total from Scores s1, Scores s2
67+
where s1.gender = s2.gender and s1.day >= s2.day
68+
group by s1.gender, s1.day
69+
order by s1.gender, s1.day

0 commit comments

Comments
 (0)