Skip to content

Instantly share code, notes, and snippets.

@cthoyt
Last active January 18, 2016 13:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cthoyt/bc262c07df6da9e6e345 to your computer and use it in GitHub Desktop.
Save cthoyt/bc262c07df6da9e6e345 to your computer and use it in GitHub Desktop.
Biological Databases Practical 2016 Day 2
/* How many countries exist */
select count(*) as num_countries
from country;
/* Select the first 10 countries and order them by name */
select *
from country
order by country.Name
limit 10;
/* How many countries exists per Contitent */
select country.Continent, count(country.Code)
from country
group by country.Continent;
/* What is the min,max,average and standard deviation surface area of all country. */
select min(country.SurfaceArea), max(country.SurfaceArea), avg(country.SurfaceArea), std(country.SurfaceArea)
from country;
/* How many languages exists per country */
select country.Name, count(countryLanguage.Language)
from country
join countryLanguage on (country.Code = countryLanguage.CountryCode)
group by country.Name;
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@cthoyt
Copy link
Author

cthoyt commented Jan 16, 2016

alternatively the second query could be construed as select 10, then order. Depending on the use case, this statement could be written as

select * 
from (select * from country limit 10)
order by country.Name;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment