3.SELECT from Nobel Tutorial

noble表

yr subject winner
1960 Chemistry Willard F. Libby
1960 Literature Saint-John Perse
1960 Medicine Sir Frank Macfarlane Burnet
1960 Medicine Peter Madawar
... ... ...

  1. 显示谁获得了1962年的文学奖Literature。
SELECT winner
  FROM nobel
 WHERE yr = 1962
   AND subject = 'Literature';
  1. 显示 爱因斯坦'Albert Einstein' 获奖的年份和科目。
SELECT yr,subject
  FROM nobel
 WHERE winner= 'Albert Einstein';
  1. 给出2000年以来,包括2000年在内的'Peace'获奖者的名字。
SELECT winner
  FROM nobel
 WHERE yr >= 2000
   AND subject = 'Peace';
  1. 显示1980年至1989年(含)的所有文学奖获奖者的详细资料(年份、学科、获奖者)。
select yr, subject, winner
from nobel
where subject = 'Literature'
and yr between 1980 and 1989;
  1. 显示所有总统获奖者的详细资料。
    Theodore Roosevelt
    Woodrow Wilson
    Jimmy Carter
    Barack Obama
SELECT * FROM nobel
 WHERE winner in ('Theodore Roosevelt','Woodrow Wilson','Jimmy Carter','Barack Obama');
  1. 显示名字为John的获奖者
select winner
  from nobel
 where winner like 'John%';
  1. 显示1980年物理学获奖者的年份、科目和姓名,以及1984年化学获奖者的姓名。
select yr,subject,winner
from nobel
where 
 (subject = 'Physics' and yr= 1980 ) 
 or
 (subject = 'Chemistry' and yr= 1984);
  1. 显示1980年除化学和医学外的获奖年份、科目和姓名。
select yr,subject,winner
from nobel
where 
 yr = 1980
 and
 subject <> 'Medicine' and subject <> 'Chemistry';
  1. 显示早期(1910年以前,不包括1910年)获得 "医学 "奖的年份、科目、姓名,以及后期(2004年以后,包括2004年)获得 "文学 "奖的人。
select yr,subject,winner
from nobel
where 
 (subject = 'Medicine' and yr < 1910 ) 
 or
 (subject = 'Literature' and yr >= 2004);
  1. 查找PETER GRÜNBERG所获奖项的所有细节。
select yr,subject,winner
from nobel
where winner = 'PETER GRÜNBERG';
  1. 查找EUGENE O'NEILL所获奖项的所有细节。

摆脱单引号
你不能直接在一个引号字符串中放入一个单引号。你可以在一个引号字符串中使用两个单引号。

select yr,subject,winner
from nobel
where winner = 'EUGENE O''NEILL';
  1. 列出获奖者、年份和主题,其中获奖者以Sir开头。先显示最近的获奖者,然后按姓名顺序排列。
select winner,yr,subject
from nobel
where winner like 'Sir%'
order by yr desc,winner;
  1. 表达式 subject IN ('Chemistry','Physics') 可以作为一个值 - 它将是0或1。

显示1984年的获奖者和科目,按科目和获奖者姓名排序,但将化学和物理列在最后。

SELECT winner, subject
  FROM nobel
 WHERE yr=1984
 ORDER BY subject IN ('Physics','Chemistry'),subject,winner;
posted @ 2021-02-04 00:14  hj0612  阅读(93)  评论(0)    收藏  举报