sqlzoo第三关select from nobel

第三关 select from nobel
  • nobel 诺贝尔获得奖的数据库表
yr(年份)sunject(奖项)winner(获奖者)
1960ChemistryWillard F . Libbay
1960LiteratureSaint-John Perse
1960MedicineSir 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降序
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值