Fork me on GitHub

sqlzoo练习15-null-quiz

sqlzoo练习15-NULL quiz

主要是对上节中学习到的NULL空值的理解与复习

NULL-quiz

练习

  1. select the code which uses an outer join correctly.
1
2
3
select teacher.name, dept.name
from teacher
left outer join dept on (teacher.dept=dept.id) -- 左连接
  1. Select the correct statement that shows the name of department which employs Cutflower -

选出雇佣了Cutfolowerl老师的系

1
2
3
4
select dept.name
from teacher
join dept on (dept.id=teacher.dept)
where teacher.name='Cutflower';
  1. Select out of following the code which uses a JOIN to show a list of all the departments and number of employed teachers

选出所有的院系和该院系雇佣的老师的数目

1
2
3
4
select dept.name, count(teacher.name)  -- 统计老师的个数
from teacher
right join dept on dept.id=teacher.dept
group by dept.name
  1. Using SELECT name, dept, COALESCE(dept, 0) AS result FROM teacher on teacher table will:
1
display 0 in result column for all teachers without department
  1. the result of Query

主要考察的是case语句的用法

1
2
3
4
5
6
select name,
case when phone=2752 then 'two'
when phone=2753 then 'three'
when phone=2754 then 'four'
end as digit
from teacher

  1. Select the result that would be obtained from the following code:
1
2
3
4
5
select name,
case when dept in (1)
then 'Computing' -- 如果dept编号是1,则标记为computing;否则是Other
else 'Other' end
from teacher;

本文标题:sqlzoo练习15-null-quiz

发布时间:2020年01月31日 - 16:01

原始链接:http://www.renpeter.cn/2020/01/31/sqlzoo%E7%BB%83%E4%B9%A015-null-quiz.html

许可协议: 署名-非商业性使用-禁止演绎 4.0 国际 转载请保留原文链接及作者。

Coffee or Tea