5 The nobel table can be used to practice more SUM and COUNT functions-SQLZoo

1. Show the total number of prizes awarded

SELECT COUNT(winner) FROM nobel;

2. List each subject - just once

select distinct subject from nobel;

3. Show the total number of prizes awarded for Physic

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(winner) 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(winner) = 3; 

10. Show winners who have won more than once

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

11. Show winners who have won more than one subject

select winner from nobel
group by winner 
having count(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(winner) = 3;
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值