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...
Q1) Connect to HR database and write the queries to answer the following questions. Provide your...
Q1) Connect to HR database and write the queries to answer the following questions. Provide your queries text and result in a .txt file: a) How many employees you can find in the Employees table b) How many departments are there in this database c) How many employees work for sales department d) What is the average salary of department 50 e) Copy Countries table from HR database into Section 24 using Select Into clause. f) Write a query to...
Give the relational algebra, tuple calculus, and SQL expressions for each using the below schema: SPERSON(EmpID,...
Give the relational algebra, tuple calculus, and SQL expressions for each using the below schema: SPERSON(EmpID, Name, Dept) TRIP(TripID, EmpID, ToCity, StartDate, EndDate) EXPENSE(ExpID, TripID, AccountID, Amount) a) List the names and employee ID of a salesperson. b) List employee ID and employee names that took a trip(s) to Charleston city. c) List the names of all employees who have spent more than $500 on their trip. d) List employees' names and their IDs that have never taken a trip....
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...
You are working with a database that stores information about suppliers, parts and projects. The Supply...
You are working with a database that stores information about suppliers, parts and projects. The Supply relation records instances of a Supplier supplying a Part for a Project. The schema for the database used in this question is as follows: (note that primary keys are shown underlined, foreign keys in bold). SUPPLIER (SNo, SupplierName, City) PART (PNo, PartName, Weight) PROJECT (JobNo, JobName, Country) SUPPLY (SNo, PNo, JobNo, Quantity) Provide relational algebra (NOT SQL) queries to find the following information. Each...
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...
. 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...