-
Notifications
You must be signed in to change notification settings - Fork 0
/
using-null.sql
51 lines (42 loc) · 929 Bytes
/
using-null.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
--1
select name from teacher where dept is null
--2
SELECT teacher.name, dept.name
FROM teacher INNER JOIN dept
ON (teacher.dept=dept.id)
--3
SELECT teacher.name, dept.name
FROM teacher LEFT JOIN dept
ON (teacher.dept=dept.id)
--4
SELECT teacher.name, dept.name
FROM teacher RIGHT JOIN dept
ON (teacher.dept=dept.id)
--5
select name, COALESCE(mobile, '07986 444 2266')
from teacher
--6
select teacher.name, COALESCE(dept.name, 'None')
from teacher left join dept on teacher.dept=dept.id
--7
select count(teacher.id), count(teacher.mobile)
from teacher
--8
select dept.name, count(teacher.id)
from teacher right join dept on teacher.dept=dept.id
group by dept.name
--9
select name, case dept
when 1 then 'Sci'
when 2 then 'Sci'
else 'Art'
end
from teacher
--10
select name, case dept
when 1 then 'Sci'
when 2 then 'Sci'
when 3 then 'Art'
else 'None'
end
from teacher