【SQL】13.SQLZOO练习8--Using Null

题目链接:https://sqlzoo.net/wiki/Using_Null

【SQL】13.SQLZOO练习8--Using Null_第1张图片
题目
【SQL】13.SQLZOO练习8--Using Null_第2张图片
1
select name from teacher 
where dept is null;
【SQL】13.SQLZOO练习8--Using Null_第3张图片
2
select a.name,b.name from teacher a
inner join dept b on a.dept=b.id;
【SQL】13.SQLZOO练习8--Using Null_第4张图片
3
select a.name,b.name from teacher a
left join dept b on a.dept=b.id;
【SQL】13.SQLZOO练习8--Using Null_第5张图片
4
select a.name,b.name from teacher a
right join dept b on a.dept=b.id;
【SQL】13.SQLZOO练习8--Using Null_第6张图片
5
select name,coalesce(mobile,'07986 444 2266') from teacher
【SQL】13.SQLZOO练习8--Using Null_第7张图片
6
select a.name,coalesce(b.name,'None') from teacher a
left join dept b on a.dept = b.id;
【SQL】13.SQLZOO练习8--Using Null_第8张图片
7
select count(name),count(mobile) from teacher;
【SQL】13.SQLZOO练习8--Using Null_第9张图片
8
select b.name,count(a.name) from teacher a
right join dept b on b.id=a.dept
group by b.name;
【SQL】13.SQLZOO练习8--Using Null_第10张图片
9
select a.name,case 
when b.id=1 then 'Sci'
when b.id=2 then 'Sci'
else 'Art' end
from teacher a left join dept b
on a.dept=b.id;
【SQL】13.SQLZOO练习8--Using Null_第11张图片
10
select a.name,case 
when b.id=1 then 'Sci'
when b.id=2 then 'Sci'
when b.id=3 then 'Art'
else 'None' end
from teacher a left join dept b
on a.dept=b.id;

你可能感兴趣的:(【SQL】13.SQLZOO练习8--Using Null)