SELECT from Nobel Tutorial
演示数据库
在本教程中,我们将使用 nobel 样本数据库。
1.更改所显示的查询,使其显示1950年的诺贝尔奖。
select yr,subiject,winner
from nobel
where yr = 1950
2,谁赢得了1962年的文学奖。
select winner
from nobel
where yr = 1962
and subject = 'literature'
3,展示获得“爱因斯坦”奖的年份和主题。
select yr,subject
from nobel
where winner = 'albert einstein'
4,给出2000年以来的“和平”获奖者的名字,包括2000年。
select winner
from nobel
where yr >= 2000 and subject = 'peace'
5,显示1980年至1989年文学奖获奖者的所有细节(yr,subject,获奖者)
select yr,subject,winner
from nobel
where yr between 1980 and 1989 and subject = 'literature'
6,显示总统获奖者的所有细节:
- Theodore Roosevelt
- Thomas Woodrow Wilson
- Jimmy Carter
- Barack Obama
select *
from nobel
where winner in ('Theodore Roosevelt',
'Thomas Woodrow Wilson',
'Jimmy Carter',
'Barack Obama')
7,顯示獲獎者名字John的
select winner
from nobel
where winner like '%john'
结论: 用Like 匹配的时候,SQL 不会忽略记录中的空格,而“=”匹配的时候,SQL会忽略掉记录中的空格,所以记录中存在空格的时候,可以用 like ‘Beds%’ 匹配,或者 =“Beds”
8,列出1980年物理获奖者和1984年化学获奖者的年份、主题和名称。
select *
from nobel
where (yr = 1980 and subject ='physics ' )
or (yr = 1984 and subject = 'chemistry')
9,显示1980年不包括化学和医学的年度、主题和获奖者姓名。
select *
from nobel
where yr = 1980
and subject not in ('chemistry', 'medicine')
10,展示当年(1910年以前,不包括1910年之前)获得“医学奖”的人的姓名,以及晚一年(2004年以后,包括2004年)的“文学”奖获得者的姓名。
select *
from nobel
where (yr < 1910 and subject = 'Medicine') or (yr >= 2004 and subject = 'literature')