0% found this document useful (0 votes)
11 views1 page

SQL Cloud

Uploaded by

rosemoses765
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views1 page

SQL Cloud

Uploaded by

rosemoses765
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

SELECT Name, Capital, Region, SurfaceArea AS "Surface Area", Population FROM

world.country ORDER BY Population;

SELECT Name, Capital, Region, SurfaceArea AS "Surface Area", Population FROM


world.country WHERE Population > 50000000 ORDER BY Population DESC;

SELECT Name, Capital, Region, SurfaceArea AS "Surface Area", Population FROM


world.country WHERE Population > 50000000 AND Population < 100000000 ORDER BY
Population DESC;

SELECT SUM(SurfaceArea) as "N. America Surface Area", SUM(Population) as "N.


America Population" FROM world.country WHERE Region = "North America";

In some cases, you might need to split a string. The following query uses
SUBSTRING_FUNCTION() to spilt a string where a space occurs. Run the following
query.

SELECT Region, substring_index(Region, " ", 1) FROM world.country;

SELECT Region FROM world.country WHERE LENGTH(TRIM(Region)) < 10;

SELECT Name, Region from world.country WHERE substring_index(Region, " ", 1) =


"Southern";

SELECT Region, substring_index(Region, " ", 1) FROM world.country;

SELECT Region, SUM(Population) FROM world.country WHERE Region = 'Australia and New
Zealand' GROUP By Region ORDER By SUM(Population) desc;

SELECT Region, Name, Population, SUM(Population) OVER(partition by Region ORDER BY


Population) as 'Running Total' FROM world.country WHERE Region = 'Australia and New
Zealand';

SELECT Region, Name, Population, RANK() OVER(partition by Region ORDER BY


Population desc) as 'Ranked' FROM world.country order by Region, Ranked;

You might also like