主要是对上节中学习到的NULL
空值的理解与复习
select teacher.name, dept.name
from teacher
left outer join dept on (teacher.dept=dept.id) -- 左连接
选出雇佣了Cutfolowerl老师的系
select dept.name
from teacher
join dept on (dept.id=teacher.dept)
where teacher.name='Cutflower';
选出所有的院系和该院系雇佣的老师的数目
select dept.name, count(teacher.name) -- 统计老师的个数
from teacher
right join dept on dept.id=teacher.dept
group by dept.name
SELECT name, dept, COALESCE(dept, 0) AS result FROM teacher
on teacher
table will:display 0 in result column for all teachers without department
主要考察的是
case
语句的用法
select name,
case when phone=2752 then 'two'
when phone=2753 then 'three'
when phone=2754 then 'four'
end as digit
from teacher
select name,
case when dept in (1)
then 'Computing' -- 如果dept编号是1,则标记为computing;否则是Other
else 'Other' end
from teacher;