\$30.00

Category:

## Description

1. Assume the following tables for this problem:

Employee(person-name, age, street, city)

Work(person-name, company-name, salary)

Company(company-name, city)

Manage(person-name, manager-name)

A person’s name is unique, but a person may work for more than one company. A company name is unique, but a company may be located in more than one city.

1. Write a query in SQL to nd the names of persons who work in one or more companies where they make a salary that is less than \$20,000.

1. Write the same query in Relational Algebra.

1. Compare the results of (a) and (b), are they the same? Why?

1. Assume the database of the previous problem and write the following queries in SQL. You should use at least one subquery in each of your answers and write each query in two signi cantly di erent ways (e.g., using di erent operators such as EXISTS, IN, and SOME)

1. Find the name(s) of the employee(s) whose total salary is higher than those of all employees living in Los Angeles.

1. Find the name(s) of the manager(s) whose total salary is higher than that of at least one employee that they manage.

1. Assume the following tables for this problem:

1. We want to nd the names and addresses of all female movie stars (gender = ’F’ in the MovieStar relation) who are also movie executives with a net worth over \$1,000,000 (netWorth > 1000000 in the MovieExec relation).

1. Write the query in SQL using INTERSECT operator.

1. Write the query in SQL without using INTERSECT operator.

1. We want to nd the movie stars who are not movie executives.

1. Write the query in SQL using EXCEPT operator.

1. Write the query in SQL without using EXCEPT operator.

1. Assume the following tables for this problem:

ComputerProduct(manufacturer, model, price)

Desktop(model, speed, ram, hdd)

Laptop(model, speed, ram, hdd, weight)

1

A computer product is either a desktop or a laptop.

1. Find the average speed of all desktop computers.

1. Find the average price of all laptops with weight below 2kg.

1. Find the average price of PC’s and laptops made by \Dell.”

1. For each di erent CPU speed, nd the average price of a laptop.

1. Find the manufacturers that make at least three di erent computer models.

1. Assume the computer-product database of the previous problem, and write the following database modi cations.

1. Using two INSERT statements, insert a desktop computer manufactured by HP, with model number 1200, price \$1000, speed 1.2Ghz, 256MB RAM, and an 80GB hard drive.

1. Using two DELETE statements, delete all desktops manufactured by IBM with price below \$1000. (Comments: Be careful with the order of your two DELETE statements.)

1. For each laptop made by Gateway, add one kilogram to the weight. (Hint: The WHERE clause in a UPDATE statement may contain complex conditions, including subqueries.)

6.Returning to the Enroll(sid, dept, cnum, sec) example which shows the enrollment f or this quarter:

1. Write an SQL query to find the students who are only enrolled in the CS classes offered this quarter.

(b) Write and SQL query to find the students who are enrolled in all the CS classes offered this quarter.

1. Write the previous queries using different SQL constructs. In particular can you express those queries using the count aggregate? Please explain.

2