Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

sql command to find out how many players score how much

I have a table like these

country gender player score year ID
Germany male Michael 14 1990 1
Austria male Simon 13 1990 2
Germany female Mila 16 1990 3
Austria female Simona 15 1990 4

This is a table in the database. It shows 70 countries around the world with player names and gender. It shows which player score how many goals in which year. The years goes from 1990 to 2015. So the table is large. Now I would like to know how many goals all female player and how many male player from Germany have scored from 2010 to 2015. So I would like to know the total score of german male player and the total score of german female player every year from 2010 to 2015 with a Sqlite

I expecting these output

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

country gender score year
Germany male 114 2010
Germany female 113 2010
Germany male 110 2011
Germany female 111 2011
Germany male 119 2012
Germany female 114 2012
Germany male 119 2013
Germany female 114 2013
Germany male 129 2014
Germany female 103 2014
Germany male 109 2015
Germany female 104 2015

>Solution :

SELECT 
country,
gender,
year,
sum(score) as score
from <table_name>
where country ='Germany' and year in ('2015','2014','2013','2012','2011','2010')
group by 1,2,3
  • filtering on country and the years you are interested in
  • then summing up total score using group by
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading