【Tips】
- sqlzoo官网链接:
- 每个系列开头介绍所用表及其信息
- 每道题均测试通过,含有题目描述、代码和结果
- 题目为自己简写,最好在官网查看具体题目
- 部分测试结果不完整,仅为一部分截图
群组函数之Nobel表练习链接:
- yr:获奖年份
- subject:获奖类别
- winner:获奖者
SELECT COUNT(subject) FROM nobel
SELECT DISTINCT subject FROM nobel
SELECT COUNT(subject) FROM nobel WHERE subject=‘Physics‘
SELECT subject,COUNT(subject) FROM nobel GROUP BY subject
SELECT subject,MIN(yr) FROM nobel GROUP BY subject
SELECT subject,COUNT(subject) 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 --奖项去重
SELECT yr,subject FROM nobel WHERE yr>=2000 GROUP BY yr,subject HAVING COUNT(winner)=3