Skip to content

Instantly share code, notes, and snippets.

@janl
Created February 8, 2013 22:05
Show Gist options
  • Save janl/4742336 to your computer and use it in GitHub Desktop.
Save janl/4742336 to your computer and use it in GitHub Desktop.
# list by how many inhabitants all in all
select district, sum(quantity) from inhabitants group by district order by sum(quantity);
# list by how many women per district
select district, sum(quantity) from inhabitants where gender = 'f' group by district order by sum(quantity);
# list by how many children per district pre-school (0-5)
select district, sum(quantity) from inhabitants where age_low = '0' group by district order by sum(quantity);
# is indeed Prenzlauer Berg the district with the most children implying as many parents as well?
# absolute numbers say yes - more than in Neukölln - but in
# percentages?
select district, sum(quantity) from inhabitants where age_low = '0' group by district order by sum(quantity);
# list by how many children per district 0-10 years old
select district, sum(quantity) from inhabitants where age_low = '0' or age_high = '10' group by district order by sum(quantity);
# list number of inhabitants without german nationality
select district, sum(quantity) from inhabitants where nationality = 'A' group by district order by sum(quantity);
# due to jus sanguin same goes for children:
select district, sum(quantity) from inhabitants where nationality = 'A' and age_low = '0' or age_high = '10' group by district order by sum(quantity);
# list in what district live the most old women
select district, age_low, sum(quantity) from inhabitants where age_low = '95' and gender = 'f' group by district, age_low order by sum(quantity);
# list female percentages for every district:
select district, round(cast(sum(case when gender = 'f' then quantity end) as decimal)/sum(quantity)*100) as prozentweibchen, sum(quantity) from inhabitants group by district order by prozentweibchen;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment