SQL题集解答-3

链接直达

1.Change the query shown so that it displays Nobel prizes for 1950.

SELECT yr,
       subject,
       winner
FROM nobel
WHERE yr = 1960

2.Show who won the 1962 prize for Literature.

SELECT winner
FROM nobel
WHERE yr = 1960
  AND subject = 'Physics'

3.Show the year and subject that won 'Albert Einstein' his prize.

SELECT yr,
       subject
FROM nobel
WHERE winner='Albert Einstein'

4.Give the name of the 'Peace' winners since the year 2000, including 2000.

SELECT winner
FROM nobel
WHERE yr>=2000
  AND subject='Peace'

5.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.Show all details of the presidential winners:

  • Theodore Roosevelt
  • Woodrow Wilson
  • Jimmy Carter
SELECT *
FROM nobel
WHERE winner IN ('Theodore Roosevelt',
                 'Woodrow Wilson',
                 'Jimmy Carter')

7.Show the winners with first name John

SELECT winner
FROM nobel
WHERE winner LIKE 'John%'

8.Show the 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.Show the winners for 1980 excluding the Chemistry and Medicine

SELECT yr,
       subject,
       winner
FROM nobel
WHERE yr=1980
  AND subject NOT IN ('Chemistry',
                      'Medicine')

10.Show 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 yr,
       subject,
       winner
FROM nobel
WHERE (yr<1910
       AND subject='Medicine')
  OR (yr>=2004
      AND subject='Literature')

11.Find all details of the prize won by PETER GRÜNBERG

SELECT *
FROM nobel
WHERE winner LIKE 'PETER GR%NBERG'

12.Find all details of the prize won by EUGENE O'NEILL

 select *
from nobel where winner like 'EUGENE O''NEILL'

13.Knights in order
List the winners, year and subject where the winner starts withSir. 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 ASC

14.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 ('Physics',
                     'Chemistry'), subject,
                                   winner
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容