We continue practicing simple SQL queries on a single table.
This tutorial is concerned with a table of Nobel prize winners:
nobel(yr, subject, winner)
Using the SELECT
statement.
1、Winers from 1950
检索1950年的诺贝尔奖信息。
Change the query shown so that it displays Nobel prizes for 1950.
SELECT yr,subject,winner FROM nobel WHERE yr=1950;
2、1962 literature
显示1962年诺贝尔文学奖得主信息。
Show who won the 1962 prize for Literature.
SELECT winner FROM nobel WHERE yr=1962 AND subject =‘Literature‘;
3、Albert Einstein
显示爱因斯坦得诺贝尔奖的时间和奖项。
Show the year and subject that won ‘Albert Einstein‘ his prize.
4、Recent Peace Prize
显示自2000年(包含2000)年至今,诺贝尔和平奖的得主。
Give the name of the ‘Peace‘ winners since the year 2000, including 2000.
SELECT winner FROM nobel WHERE subject=‘Peace‘ AND yr>=2000;
5、Literature in 1980‘s
显示从1980-1989年诺贝尔文学奖的所有信息。
Show all details (yr, subject, winner) of the Literature prize winners for 1980 to 1989 inclusive.
SELECT * FROM nobel WHERE subject=‘Literature‘ AND yr BETWEEN 1980 AND 1989;
6、Only presidents
显示总统得主‘西奥多·罗斯福’,‘伍德罗·威尔逊’,‘吉米·卡特’,‘巴拉克·奥巴马’的所有信息。
Show all details of the presidential winners:
- Theodore Roosevelt
- Woodrow Wilson
- Jimmy Carter
- Barack Obama
SELECT * FROM nobel WHERE winner IN(‘Theodore Roosevelt‘,‘Woodrow Wilson‘,‘Jimmy Carter‘,‘Barack Obama‘);
7、John
显示名为‘John’的诺贝尔奖得主姓名。
Show the winners with first name John
SELECT winner FROM nobel WHERE winner LIKE ‘John%‘;
8、Chemistry and Physics from different years
显示1980年诺贝尔物理学和1984年诺贝尔化学奖得主的年份,奖项,姓名。
Show the year, subject, and name of Physics winners for 1980 together with the Chemistry winners for 1984.
SELECT yr,subject,winner FROM nobel WHERE subject=‘Physics‘ AND yr=1980 OR subject=‘Chemistry‘ AND yr=1984;
9、Exclude Chemists and medics
显示1980年诺贝尔除化学和药学之外的所有信息。
Show the year, subject, and name of winners for 1980 excluding Chemistry and Medicine
SELECT * FROM nobel WHERE yr=1980 AND subject NOT IN (‘Chemistry‘,‘Medicine‘);
10、Early medicine,Later Literature
显示1910年以前(不包含1910年)医药学得奖信息和2004年后(包含2004年)的文学奖得奖信息。
Show year, subject, and name of people who won a ‘Medicine‘ prize in an early year (before 1910, not including 1910) together with winners of a ‘Literature‘ prize in a later year (after 2004, including 2004)
SELECT * FROM nobel WHERE subject=‘Medicine‘ AND yr <1910 OR subject=‘Literature‘ AND yr>=2004;
11、Umlaut
显示PETER GRÜNBERG的得奖信息。
Find all details of the prize won by PETER GRÜNBERG
SELECT * FROM nobel WHERE winner=‘PETER GRÜNBERG‘;
12、apostrophe
显示EUGENE O‘NEILL的得奖信息。
Find all details of the prize won by EUGENE O‘NEILL
SELECT * FROM nobel WHERE winner=‘EUGENE O‘NEILL‘;
13、Knights of the realm
Knights in order
罗列以‘Sir’开头的得奖者姓名,年份,得奖项信息,年份按照最近排序,然后按照名字排序
List the winners, year and subject where the winner starts with Sir. Show the the most recent first, then by name order.
SELECT winner,yr,subject FROM nobel WHERE winner LIKE ‘Sir%‘ ORDER BY yr DESC,winner;
14、Chemistry and Physics Last
The expression subject IN (‘Chemistry‘,‘Physics‘) can be used as a value - it will be 0 or 1.
Show the 1984 winners and subject ordered by subject and winner name; but list Chemistry and Physics last.
SELECT winner, subject FROM nobel WHERE yr=1984 ORDER BY subject IN(‘Chemistry‘,‘Physics‘),subject,winner;