5.Use COALESCE to print the mobile number. Use the number ‘07986 444 2266’ if there is no number given. Show teacher name and mobile number or ‘07986 444 2266’
select name, ifnull(mobile,‘07986 444 2266’)
from teacher
6.Use the COALESCE function and a LEFT JOIN to print the teacher name and department name. Use the string ‘None’ where there is no department.
select teacher.name, ifnull(dept.name, ‘None’) as department
from teacher
left join
dept
on teacher.dept = dept.id
10.Use CASE to show the name of each teacher followed by ‘Sci’ if the teacher is in dept 1 or 2, show ‘Art’ if the teacher’s dept is 3 and ‘None’ otherwise.
select teacher.name, case
when teacher.dept in (1,2)
then ‘Sci’
when teacher.dept in (3)
then ‘Art’
else ‘None’
end
from teacher