Question

Using the Company database in Oracle, construct SQL queries for the following (note: I will make...

Using the Company database in Oracle, construct SQL queries for the following (note: I will make the files to create and populate the Company database available on Isadore shortly):

  1. List the last name and address of managers who have a dependent with the same first name as themselves.

  1. Retrieve the names of all employees who are directly supervised by ‘Franklin Wong’.

  1. Retrieve the names of employees in the Research department who work more than 20 hours per week on the 'Computerization' project.

  1. List the last names of all supervisors who have no dependents.

  1. For each department, retrieve the department name and the minimum salary for all employees working in that department.

  1. For each department whose average employee salary is more than $30,000, retrieve the department name and the number of employees working for that department.

  1. Retrieve the average salary of female employees who work more than 20 hours on projects.

  1. Retrieve the names of employees who work on every project that John Smith works on.

  1. Find the names and addresses of employees who work on at least one project located in Houston, but whose department has no location in Houston.

  1. Create a view that has the employee name, supervisor name, and employee salary for each employee who works in the ‘Research’ department.

  1. Create a view that has project name, controlling department number, number of employees, and total hours worked per week on the project (group by project name).

Homework Answers

Answer #1

1.For an employee database that looks as follows, P,ease find all the queries mentioned below.

Select lname, address 
from Employee as e
Inner join dependent as d
Using (emp_id)
where e.last_name=d.dependent_name and e.designation like 'Manager'

2.

Select fname, lname 
from employee as e
where e.superssn =(Select ssn from employee where fname like 'Franklin' and lname like 'Wong');

3.

select fname,lname from employee as e

inner join department as d

on 

e.dno=d.number

inner join works_on as w

on 
e.ssn=w.essn

inner join project as p
w.pno=p.pnumber

where d.dname like 'Research' and w.hours>20 and p.pname="Computerization";

4.

Select fname,lname 
from employee as e

where e.superssn is not null and e.ssn not in (select essn from dependent);


5.

select dname, min(salary) as Min_Salary
from department as d
inner join employee as e
on e.dno=d.dnumber
group by dname;

6.

select dname, count(ssn) as Count_Emp
from department as d
inner join employee as e
on e.dno=d.dnumber
where e.salary>30000
group by dname;

7.

select avg(salary) as avg_salary 
from employee as e
inner join works_on as w
on e.ssn=w.essn
where e.sex= 'Female' ;

8.

select fname,lname 
from employee as e
inner join works_on as w
on e.ssn=w.essn
where w.pno in (select pno from works_on as w
                    inner join employee as e 
                     on e.ssn=w.essn 
                     where e.fname='John' and lname='Smith');

9.

select fname,lname , adress from employee as e
inner join works_on as w
on e.ssn=w.essn
inner join project as p
on w.pno=p.pnumber
inner join dept_location as dl 
on e.dno=dl.dnumber
where
p.plocation like 'Houston' and dl.dlocation not like 'Houston' ;

10.

select fname,lname, sname, salary 
from employee as e 
inner join department as d
on e.dno=d.dnumber
where d.dname ='Research' ;

11.

Select pname,dnumber,count(ssn) as No_of_emp,hours 
from employees as e
inner join department as d
on d.dnumber=e.dno
inner join works_on as w
on w.essn=e.ssn
inner join project as p
on w.pno =p.pnumber
group by pname;

Please mention any doubts in comments.Thanks

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Specify the following queries in SQL on the COMPANY database. Show the result of each query....
Specify the following queries in SQL on the COMPANY database. Show the result of each query. Retrieve the names of all employees in department 5 who work more than 10 hours per week on the ‘ProductX’ project. List the names of all employees who have a dependent with the same first name as themselves. Find the names of all employees who are directly supervised by ‘Franklin Wong’. Specify the following updates using the SQL update commands. Show the state of...
Consider the following relational schema (the primary keys are underlined and foreign keys are italic) ITEM(ItemName,...
Consider the following relational schema (the primary keys are underlined and foreign keys are italic) ITEM(ItemName, ItemType, ItemColour) DEPARTMENT(Deptname, DeptFloor, DeptPhone, Manager) EMPLOYEE(EmpNo, EmpFname, EmpSalary, DeptName, SupervisedBy) SUPPLIER(SupNo, SupName) SALE(SaleNo, SaleQty, ItemName, DeptName) DELIVERY(DeliNo, DeliQty, ItemName, DeptName, SupNo) Write the SQL statements for the following queries: C1. Find the names of items sold on first and second floors. [1 mark] C2. For each department, list the department name and average salary of the employees where the average salary of the...
Write the following questions as queries in SQL. Use only the operators discussed in class (in...
Write the following questions as queries in SQL. Use only the operators discussed in class (in particular, no outer joins or windows). Type your answers. Before starting, make sure you understand the schema of the database. If you are in doubt about it, please ask the instructor. Assume a database with schema ACTOR(name,age,address,nationality) MOVIE(title,year,genre,budget,director-name,studio) APPEARS(name,title,salary) 1. Find the title, director and studio of the most expensive movie of 2010 (note: there can be ties!). 2. Find the title, director and...
1. Consider the following tables in a relational database. Provide the appropriate "SELECT" SQL statement necessary...
1. Consider the following tables in a relational database. Provide the appropriate "SELECT" SQL statement necessary to answer the queries that follow. Primary keys are underlined and foreign key fields have an asterisk at the end of the field. CUSTOMERS (CUST-NO, C-NAME, C-ADDRESS, BALANCE) SALESPERSONS (SP-NO, S-NAME, DATE-EMPLOYED, SALARY) SALES (INVOICE-NO, DATE, CUST-NO*, SP-NO*) a) List the salesperson name and salary for all sales to customers whose balance outstanding is greater than 20000. b) List the names and addresses of...
Design ER diagram to capture the information below and explain fully your answer: The University has...
Design ER diagram to capture the information below and explain fully your answer: The University has to create a database. In design stage the committee formed the following description: “The research activity at the University is organized as series of projects: Each project has project number, budget, funding organization, staring date and completion date. Each project has a PI who is full time faculty at the university. Each project has only one PI, but can have one or more Co-PI...
Prevosti Farms and Sugarhouse pays its employees according to their job classification. The following employees make...
Prevosti Farms and Sugarhouse pays its employees according to their job classification. The following employees make up Sugarhouse's staff: The departments are as follows: Department A: Agricultural Workers Department B: Office Workers The first day of work for Prevosti Farms and Sugarhouse for all employees is February 4, 2019. February 8 is the end of the first pay period and includes work completed during the week of February 4–8. Compute the employee gross pay using 35 hours as the standard...
***This is a complete question. Do not tag this as incomplete. Write SQL queries to the...
***This is a complete question. Do not tag this as incomplete. Write SQL queries to the below Relational Database. • Regarding the SQL queries: • Do not use SELECT * in any query. • Do not use any SQL features (including Nullif) that were not covered in this course. • Do not use subqueries IF joins can be used to answer a question. However, some questions may require the use of subqueries. The Movie Database Notes: TheaterNum, MovieNum, and ActorNum...
Summary The Ch08_ConstructCo database stores data for a consulting company that tracks all charges to projects....
Summary The Ch08_ConstructCo database stores data for a consulting company that tracks all charges to projects. The charges are based on the hours each employee works on each project. The structure and contents of the Ch08_ConstructCo database are shown in Figure P8.1. Use this database to answer the following problems. Database Schema The schema for the Ch08_ConstructCo database is shown below and should be used to answer the next several problems. Click this image to view it in its own...
Find the total number of employees and the total number of dependents for every department (the...
Find the total number of employees and the total number of dependents for every department (the number of dependents for a department is the sum of the number of dependents for each employee working for that department). Return the result as department name, total number of employees, and total number of dependents Based on the following table: -- drop tables DROP TABLE EMPLOYEE CASCADE CONSTRAINTS; DROP TABLE DEPARTMENT CASCADE CONSTRAINTS; DROP TABLE DEPT_LOCATIONS CASCADE CONSTRAINTS; DROP TABLE PROJECT CASCADE CONSTRAINTS;...
Calculate net pay for the following employee in Alberta with basic federal and provincial claim code....
Calculate net pay for the following employee in Alberta with basic federal and provincial claim code. 1. Each of the employees will receive benefits: Group term life insurance $25.00 per month. Taxable car allowances $12 per pay 2. Each of the employees will have deductions: RRSP 3% of regular salary Union dues $25.00 per pay. • Employee number one will be a salaried employee earning $65,000 per year, paid bi-weekly, working in the marketing department, was born on February 13,...