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...
Oracle Assingment Introduction to databases Topics :Restricting and sorting data Create a query to display the...
Oracle Assingment Introduction to databases Topics :Restricting and sorting data Create a query to display the last name and salary of employees earning more than 1200 Display the last name and salary for all employees whose salary is not in the range of 5,000 and 10,000 Display the employee last name, job ID, and start date of employees hired between February 20, 1998, and May 1, 1998. Order the query in ascending order by start date. Display the last name...
Write the following SQL queries based on hbsoe database from Mode: Select all the employee information...
Write the following SQL queries based on hbsoe database from Mode: Select all the employee information and list them for first 100 only. Select all the order information from country Germany. How many distinct orders are made from each country? List the names of employees who made orders from country Germany. List the names of companies which supplies chai or tofu
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...
. Design an ER-diagram for a bank that implements the following requirements. The database you design...
. Design an ER-diagram for a bank that implements the following requirements. The database you design should store information about customers, accounts, branches and employees • Customer: Customers are identified by their SSN. For each customer we store a name, multiple phone numbers (one or more), and an occupation. • Account: Accounts are identified by an account number and the branch they belong to. For each account we store a balance and the type of account (e.g., savings). – An...
Write the following four queries in MySQL using the supplies database. Please make sure to submit...
Write the following four queries in MySQL using the supplies database. Please make sure to submit a screenshot of the output of each of your query. (100 points) 1. Find the sids of suppliers who charge more for some part than the average cost of that part (averaged over all the suppliers who supply that part). 2. For each part, find the sname of the supplier who charges the most for that part. 3. Find the sids of suppliers who...
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...
Draw the Crow’s Foot database notation entity-relationship diagrams (ERD) to represent the databases, based on the...
Draw the Crow’s Foot database notation entity-relationship diagrams (ERD) to represent the databases, based on the three narratives below. Use Lucid Chart or another ERD diagramming tool to create your diagram. You do not need to create the databases, but to design it using applicable business rules according to your judgment. Submit a PDF of the Entity Relationship Diagram for each database. Remember to identify in your diagrams: All the main entities and the main attributes for each entity The...
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...