【Tips】
- sqlzoo官网链接:
- 每个系列开头介绍所用表及其信息
- 每道题均测试通过,含有题目描述、代码和结果
- 题目为自己简写,最好在官网查看具体题目
- 部分测试结果不完整,仅为一部分截图
NULL值之苏格兰议会练习链接:
1.NULL值选择
SELECT name FROM msp WHERE party IS NULL
SELECT name,Leader FROM party
SELECT name,Leader FROM party WHERE Leader IS NOT NULL
SELECT party.name FROM party JOIN msp ON Code=Party GROUP BY party.name HAVING COUNT(party.name)>=1
5.列出议会成员的名单,如果有所属政党,一同列出
SELECT msp.name,party.name FROM msp LEFT JOIN party ON Party=Code ORDER BY msp.name
SELECT party.name,COUNT(msp.name) FROM msp LEFT JOIN party ON Party=Code WHERE Party IS NOT NULL GROUP BY party.name
SELECT party.name,COUNT(msp.name) FROM msp RIGHT JOIN party ON Party=Code GROUP BY party.name