5.1.SUM and COUNT MORE
nobel(yr, subject, winner)
- 显示获奖总数。
SELECT COUNT(winner) FROM nobel;
- 列出每个主题--只需一次
select distinct subject from nobel;
- 显示物理学获奖总数。
select count(winner)
from nobel
where subject ='Physics';
- 对每个科目显示科目和奖号。
select subject, count(winner)
from nobel
group by subject;
- 每个科目显示出获奖的第一年。
select subject, min(yr)
from nobel
group by subject;
- 每一个科目都显示2000年的获奖人数。
select subject, count(winner)
from nobel
where yr = 2000
group by subject;
- 显示每个科目的不同获奖人数。
select subject, count(distinct winner)
from nobel
group by subject;
- 对于每个科目,显示有多少年获得过奖项。
select subject, count(distinct yr)
from nobel
group by subject;
- 出示物理学获得三个奖项的年份。
select yr
from nobel
where subject = 'Physics'
group by yr
having count(winner) = 3;
- 显示获奖者已经超过一次。
select winner
from nobel
group by winner
having count(winner)>1;
- 显示获奖者已超过一个科目。
select winner
from nobel
group by winner
having count(distinct subject)>1;
- 显示获得3个奖项的年份和主题。只显示2000年以后的年份。
select yr, subject
from nobel
where yr>=2000
group by yr,subject
having count(winner)=3