sqlzoo第三关select from nobel

第三关 select from nobel

  • nobel 诺贝尔获得奖的数据库表
yr(年份) sunject(奖项) winner(获奖者)
1960 Chemistry Willard F . Libbay
1960 Literature Saint-John Perse
1960 Medicine Sir Frank Macfarlane Burnet
3.1 题目及答案
  1. 更改查询以显示1950年诺贝尔奖的奖项资料。
SELECT yr, subject, winner 
	FROM nobel  
	WHERE yr = 1950
  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年及以后的和平奖(‘Peace’)得奖者。
select winner from nobel where subject = 'Peace' and yr>=2000
  1. 显示1980年至1989年(包含首尾)的文学奖(Literature)获奖者所有细节(年,奖项,获奖者)。
select * 
	from nobel 
	where yr between 1980 and 1989 and subject = 'Literature'
  1. 显示总统获奖者的所有细节:
  • 西奥多·罗斯福 Theodore Roosevelt
  • 伍德罗·威尔逊 Woodrow Wilson
  • 洁米·卡特 Jimmy Carter
SELECT * FROM nobel
 WHERE winner IN ('Theodore Roosevelt',
                  'Woodrow Wilson',
                  'Jimmy Carter')
  1. 显示名字为John的得奖者。(注意:外国人名字(First name)在前,姓氏(Last name)在后)。
select winner from nobel where winner like 'John%'
  1. 显示1980年物理学(physics)获奖者,及1984年化学奖(chemistry)获奖者。
select * from nobel 
	where (yr = 1980 and subject = 'physics')
	 or (yr = 1984 and subject = 'chemistry')
  1. 查看1980年获奖者,但不包含化学奖(Chemistry)和医学奖(Medicine)。
select * from nobel where yr = 1980 and subject not in ('Chemistry','Medicine')
  1. 显示早期的医学奖(Medicine)得奖者(1910之前,但不包括1910),及近年文学奖(Literature)得奖者(2004年以后,包括2004年)。
select * from nobel 
	where (yr < 1910 and subject = 'Medicine') 
	or (yr >= 2004 and subject = 'Literature')
  • 困难的题目
  1. 查找 ‘PETER GRÜNBERG’ 获奖者的所有详细信息。
select * from nobel where winner = 'PETER GRÜNBERG'
  1. 查找 “EUGENE O’NEILL” 获奖者的所有详细信息。
select * 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. 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
3.2总结
函数 用法说明
order by 一列或者多列的值,或者是指定的具体值,按照升序或者降序排列数据,ASC升序,DESC降序
发布了33 篇原创文章 · 获赞 1 · 访问量 1436

猜你喜欢

转载自blog.csdn.net/smileKutper/article/details/103763181