User:Marek
Temp reference
Counter with Local Storage
You have visited the page
times.
Test qu2 tutorial questions
The example shows the population of 'France'. Strings should be in 'single quotes';
Show the population of Germany
SELECT population FROM bbc
WHERE name = 'France'
SELECT population FROM bbc
WHERE name = 'Germany'
population/area
for each country where the area is over 5,000,000 km2.gdp/population
for each country where the area is over 5,000,000 km2SELECT name, population/area FROM bbc
WHERE area > 5000000
SELECT name, gdp/population FROM bbc
WHERE area > 5000000
Where to find some very small, very rich countries.
We use AND
to ensure that two or more conditions hold
true.
SELECT name , region
FROM bbc
WHERE population < 2000000
AND gdp > 5000000000
SELECT name , region
FROM bbc
WHERE area < 2000
AND gdp > 5000000000
Checking a list The word IN allows us to check if an item is in a list. The example shows the name and population for the countries 'Ireland', 'Iceland' and 'Denmark'
SELECT name, population FROM bbc
WHERE name IN ('Ireland', 'Iceland',
'Denmark')
SELECT name, population FROM bbc
WHERE name IN ('Denmark', 'Finland',
'Norway', 'Sweden')
What are the countries beginning with G?
The word LIKE
permits pattern matching - % is the wildcard.
The examples shows countries beginning with D
SELECT name FROM bbc
WHERE name LIKE 'D%'
SELECT name FROM bbc
WHERE name LIKE 'G%'
Quiz Test
<quiz shuffle=none display=simple> {In a SELECT statement indicate the part that determines which rows are displayed |type="()"} - CHOOSE - GROUP BY - ORDER BY - HAVING + WHERE
{Select the statement that shows the population of 'United Kingdom' |type="()"} - GIVE population OF 'United Kingdom' - SELECT name FROM bbc WHERE population = 'United Kingdom' + SELECT population FROM bbc WHERE name = 'United Kingdom' - SELECT population FROM 'United Kingdom' WHERE name = 'population' - SELECT 'United Kingdom', population FROM bbc
{Select the statement that shows the sum of population of all countries in 'Europe' |type="()"} - SELECT name, population FROM bbc WHERE region = 'Europe' - SELECT population FROM bbc WHERE region = 'Europe' SUM BY region + SELECT SUM(population) FROM bbc WHERE region = 'Europe' - SELECT SUM(population FROM bbc WHERE region = 'Europe') - SUM population FROM bbc WHERE region = 'Europe'
{Select the statement that shows the number of countries with population smaller than 150000 |type="()"} + SELECT COUNT(name) FROM bbc WHERE population < 150000 - SELECT COUNT(population < 150000) FROM bbc - SELECT name FROM bbc WHERE population < 150000 - SELECT population AS COUNT FROM bbc WHERE population < 150000 - SELECT SUM() FROM bbc WHERE population < 150000
{Select the full set of SQL aggregate functions |type="()"} - AVG(), COUNT(), FIRST(), LAST(), SUM() - AVG(), COUNT(), MAX(), MEDIAN(), MIN(), ROUND(), SUM() + AVG(), COUNT(), FIRST(), LAST(), MAX(), MIN(), SUM() - AVG(), COUNT(), MAX(), MIN(), SUM() - COUNT(), SUM()
{Select the statement that shows the average population of 'Poland', 'Germany' and 'Denmark' |type="()"} - SELECT AVG(population) FROM bbc WHERE name = ('Poland', 'Germany', 'Denmark') + SELECT AVG(population) FROM bbc WHERE name IN ('Poland', 'Germany', 'Denmark') - SELECT AVG(population) FROM bbc WHERE name LIKE ('Poland', 'Germany', 'Denmark') - SELECT AVG(population) FROM bbc WHERE name LIKE (Poland, Germany, Denmark) - SELECT population FROM bbc WHERE name IN ('Poland', 'Germany', 'Denmark')
{Select all the statements that show all the countries in 'Africa' |type="[]"} - SHOW country WHERE region = 'Africa' - SELECT country WHERE region LIKE 'Africa' + SELECT name FROM bbc WHERE region LIKE 'Africa' + SELECT name FROM bbc WHERE region = 'Africa' - SELECT region = 'Africa' FROM bbc </quiz>