0% found this document useful (0 votes)
8 views

For the Following Relation Schema

Uploaded by

rashmimaruthi2
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

For the Following Relation Schema

Uploaded by

rashmimaruthi2
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

For the following relation schema:

employee(employee-name, street, city)


works(employee-name, company-name, salary)
company(company-name, city)
manages(employee-name, manager-name)

1. Find the names, street address, and cities of residence for all employees who work for 'First Bank
Corporation' and earn more than $10,000.
2. Find the names of all employees in the database who live in the same cities as the companies for
which they work.

3. Find the names of all employees in the database who live in the same cities and on the same
streets as do their managers.

4. Find the names of all employees in the database who do not work for 'First Bank Corporation‘

5. Find the names of all employees in the database who earn more than every employee of 'Small
Bank Corporation'. Assume that all people work for at most one company.

6. Assume that the companies may be located in several cities. Find all companies located in every city in
which 'Small Bank Corporation' is located

7. Find the names of all employees who earn more than the average salary of all employees of their
company. Assume that all people work for at most one company.

8. Find the name of the company that has the smallest payroll.

Answers

1. select employee.employee-name, employee.street, employee.city from employee, works where


employee.employee-name=works.employee-name and company-name = 'First Bank Corporation' and
salary > 10000)

2. select e.employee-name from employee e, works w, company c where e.employee-name =


w.employee-name and e.city = c.city and w.company-name = c.company-name

3. select p.employee-name from employee p, employee r, manages m where p.employee-name =


m.employee-name and m.manager-name = r.employee-name and p.street = r.street and p.city = r.city

4. select employee-name from works where company-name <> 'First Bank Corporation'

5. select employee-name from works where salary > all (select salary from works where company-name
= 'Small Bank Corporation')
6. select s.company-name from company s where not exists ((select city from company where company-
name = 'Small Bank Corporation') except (select city from company t where s.company-name =
t.company-name))

7. select employee-name from works t where salary >(select avg(salary) from works s where t.company-
name = s.company-name)

8. select company-name from works group by company-name having sum(salary) <= all (select
sum(salary) from works group by company-name)

CUSTOMER (cust #: int , cname: string, city: string)

ORDER (order #: int, odate: date, cust #: int, ord-Amt: int)

ORDER – ITEM (order #: int, Item #: int, qty: int)

ITEM (item # : int, unit price: int)

SHIPMENT (order #: int, warehouse#: int, ship-date: date)

WAREHOUSE (1. List the no. of order placed by customer no. 5

2. List item nos and and its quantity of order no. 5

3. List the average order amount where "for the current year“

4. List the no. of orders placed by each customer

5. List the customer names who have not ordered for item no. 10.

6. List warehouse #: int, city: string)

customer details who has the largest order amount

7. List the names of customers who have ordered at least 10 items

• 1. SELECT COUNT(CO.ORDERNO) FROM CORDER CO WHERE CO.CUSTNO = 5;


• 2. SELECT ITEMNO,QTY FROM ORDERITEM WHERE ORDERNO = 5;
• 3. SELECT AVG(ORDAMT) FROM CORDER WHERE ODATE LIKE '%13';
• 4. SELECT COUNT(*) FROM CORDER GROUP BY CUSTNO;
• 5. SELECT C.ENAME FROM CUSTOMER C,CORDER CO
WHERE C.CUSTNO = CO.CUSTNO AND CO.ORDERNO != 10;
• 6. SELECT C.ENAME,C.CUSTNO,C.CITY FROM CUSTOMER C,CORDER CO
WHERE C.CUSTNO = CO.CUSTNO AND CO.ORDAMT =
(SELECT MAX(CO.ORDAMT) FROM CORDER CO);
• 7. SELECT C.ENAME,COUNT(*) FROM CUSTOMER C,CORDER CO
WHERE C.CUSTNO = CO.CUSTNO GROUP BY C.ENAME HAVING COUNT(*) >= 10;

You might also like