You are on page 1of 3

ECSI411 Information Systems 2013-2014 Tutorial 04

Exercise 01
1.1. Write a query for the HR department to produce the full addresses of all the departments. Use the LOC !"O#$ and COU#!R"E$ ta%les. $ho& the location "'( street address( city( state or pro)ince( and country in the output.

SELECT location_id,street_address,city,state_province,Countries.country_id,country_name FROM Locations JOI Countries O locations.country_id!countries.country_id" OR SELECT location_id,street_address,city,state_province,c.country_id,country_name FROM Locations l JOI Countries c O l.country_id!c.country_id"

Exercise 0*
*.1. !he HR department needs a report of all employees &ho &ere hired after the *+ ,arch 1--.. Write a query to display the last name( department num%er( and department name for all employees hired after that date. SELECT last_name,e.department_id, department_name FROM Employees e JOI #epartments d O e.department_id! d.department_id $%ERE &ire_date'()*+M,R+-../(

*.* ,odify the pre)ious query to also add the departments &ho ha)e no employees. SELECT last_name,e.department_id, department_name FROM Employees e LEFT O0TER JOI #epartments d O e.department_id! d.department_id $%ERE &ire_date'()*+M,R+-../( "

Exercise 0.
..1. !he HR department needs a report of employees in !oronto. 'isplay the last name( /o%( department num%er( and department name for all employees &ho &or0 in !oronto. SELECT last_name,1o2_title,d.department_id,department_name FROM Employees e , #epartments d,Locations l , Jo2s 1 $%ERE l.city!(Toronto( , # e.department_id ! d.department_id , # d.location_id! l.location_id , # e.1o2_id!1.1o2_id"

Exercise 01
1.1. Create a report to display employees2 last name and employee num%er alon3 &ith their mana3er2s last name and mana3er num%er. La%el the columns Employee( Emp4( ,ana3er( and ,3r4( respecti)ely. SELECT last_name ,S Employee , employee_id ,S 3Emp45, mana6er_name ,S Mana6er , e.manager_id ,S 3M6r45 FROM Employees e JOI Mana6ers m O e.mana6er_id! m.mana6er_id $%ERE e. mana6er_id IS OT 0LL " 1.*. ,odify the pre)ious query to display all employees includin3 5in3( &ho has no mana3er. Order the results %y the employee num%er. SELECT last_name ,S Employee , employee_id ,S 3Emp45, mana6er_name ,S Mana6er ,manager_id ,S 3M6r45 FROM Employees e LEFT O0TER JOI Mana6ers m O e.mana6er_id! m.mana6er_id OR#ER 78 employee_id"

You might also like