The nobel table can be used to practice more SUM and COUNT functions.

1.Show the total number of prizes awarded.

`SELECT count(subject) FROM nobel`

2.List each subject - just once

 `SELECT distinct subject FROM nobel`

3.Show the total number of prizes awarded for Physics

` SELECT count(winner) FROM nobel
  where subject='Physics'`

4.For each subject show the subject and the number of prizes.
SELECT subject ,count(winner) FROM nobel
group by subject

5.For each subject show the first year that the prize was awarded.

`select subject , min(yr) from nobel
group by subject`

6.For each subject show the number of prizes awarded in the year 2000.

`select subject,count(subject) from nobel

where yr=2000 group by subject`

7.Show the number of different winners for each subject.

 `select subject,count(distinct (winner)) from nobel
group by subject `

8.For each subject show how many years have had prizes awarded.

`select subject ,count(distinct yr) from nobel
group by subject`

9.Show the years in which three prizes were given for Physics.

`select yr from nobel
where subject='Physics' group by yr having count(subject)=3`

10.Show winners who have won more than once.

`select winner from nobel
 group by winner having count(winner)>1`

11Show winners who have won more than one subject.

` select winner from nobel
 group by winner having count(distinct(subject))>1`

12.Show the year and subject where 3 prizes were given. Show

`only years 2000 onwards.
select yr, subject from nobel
where yr>=2000 group by yr,subject having count(*)=3`
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值