發表文章

目前顯示的是 12月, 2019的文章

SQL ZOO PART 2 : SUM and COUNT & The JOIN operation

圖片
承接 上一篇  的練習, 這次繼續玩下去~~~ SUM and COUNT https://sqlzoo.net/wiki/SUM_and_COUNT 1.  Show the total  population  of the world. SELECT SUM(population) FROM world 2.  List all the continents - just once each. SELECT DISTINCT(continent) FROM world 3.  Give the total GDP of Africa SELECT SUM(gdp) from world where continent like 'Africa' 4.  How many countries have an  area  of at least 1000000 SELECT COUNT(name) FROM world WHERE area > 1000000 5.  What is the total  population  of ('Estonia', 'Latvia', 'Lithuania') SELECT SUM(population) FROM world where name in ('Estonia', 'Latvia', 'Lithuania') 6.  For each  continent  show the  continent  and number of countries. SELECT continent, COUNT(name) FROM world GROUP BY continent 7.  For each  continent  show the  continent  and number of countries with populations of at least 10 million. SELECT continent...

SQL ZOO PART 1 : SELECT from nobel & SELECT within SELECT

SQL ZOO 練習 SQL ZOO是蠻適合新手練習SQL語法的地方,這次單純將練習時的結果紀錄下來,Nobel以前的章節都蠻基礎,nobel則是綜合前面章節的小練習,所以來試試看~ 第二段SELECT WITHIN SELECT則是巢狀的應用,稍微複雜不過稍為看一下不會太難懂 SELECT from Nobel https://sqlzoo.net/wiki/SELECT_from_Nobel_Tutorial 1.  Change the query shown so that it displays Nobel prizes for 1950. SELECT * FROM nobel WHERE yr = 1950 2.  Show who won the 1962 prize for Literature. SELECT winner FROM nobel WHERE yr = 1962 AND subject = 'Literature' 3.  Show the year and subject that won 'Albert Einstein' his prize. SELECT yr, subject FROM nobel WHERE winner LIKE 'Albert Einstein' 4.  Give the name of the 'Peace' winners since the year 2000, including 2000. SELECT winner FROM nobel WHERE subject LIKE 'Peace' AND yr >= 2000 5.  Show all details ( yr ,  subject ,  winner ) of the Literature prize winners for 1980 to 1989 inclusive. SELECT*FROM nobel WHERE subject LIKE 'Literature' AND yr BETWEEN 1980 AND 1989 6.  Show...