Presentation is loading. Please wait.

Presentation is loading. Please wait.

COP Introduction to Database Structures

Similar presentations


Presentation on theme: "COP Introduction to Database Structures"— Presentation transcript:

1 COP 3540 - Introduction to Database Structures
SQL II

2

3 Relations sailors

4 Relations boats reserves

5 sailors s, reserves r, boats b
Find the names and ages of all sailors. Find all sailors with a rating above 7. Find the names of sailors who have reserved boat number 103. Find the sids of sailors who have reserved a red boat. Find the colors of boats reserved by Lubber. Find the names of sailors who have reserved at least one boat. Compute increments 1 for the rating of persons who have sailed two different boats on the same day.

6 sailors s, reserves r, boats b
Find the names of sailors who have reserved a red or a green boat. Find the names of sailors who have reserved both a red and a green boat. Find the sids of all sailors who have reserved red boats but not green boats. Find all sids of sailors who have a rating of 10 or reserved boat 104. Find the names of sailors who have reserved boat 103. Find the names of sailors who have reserved a red boat. Find the names of sailors who have not reserved a red boat.

7 sailors s, reserves r, boats b
Find the names of sailors who reserved at least one boat and have not reserved a red boat. Find the names of sailors who have reserved boat number 103. Find sailors whose rating is better than some sailor called Horatio. Find sailors with the highest rating. Find the names of sailors who have reserved both a red and a green boat. Find the names of sailors who have reserved all boats Find the average age of all sailors. Find the average age of sailors with a rating of 10.

8 sailors s, reserves r, boats b
Find the name and age of the oldest sailor. Count the number of sailors Count the number of different names; Find the names of sailors who are older than the oldest sailor with a rating of 10. Find the age of the youngest sailor for each rating level. Fine the age of the youngest sailor who is eligible to vote (i.e., is at least 18 years old) for each rating level with at least two such sailors. Find the age of the youngest sailor who is eligible to vote (i.e., is at least 18 years old) for each rating level with at least two such sailors and all sailors in each rating level are at most 60 years old.

9 sailors s, reserves r, boats b
For each red boat, find the number of reservations for this boat. Find the average age of sailors for each rating level that has at least two sailors Find the average age of sailors who are of voting age (i.e., at least 18 years old) for each rating level that has at least two sailors. Find the average age of sailors who are of voting age (i.e., at least 18 years old) for each rating level that has at least two such sailors. Find those ratings for which the average age of sailors is the minimum over allratings.

10

11 Relations

12 Relations

13 Relations

14 Relations

15 Relations

16 employee e, work_on w, project p, department d
Retrieve the birth date and address of the employee whose name is 'John B.Smith'. For every project located in 'Stafford', list the project number, the controlling department number, and the department manager's last name, address, and birth date. List the names and addresses of employees who worked in 'Research' department. For each employee, retrieve the employee's first and last name and the first and last name of his or her immediate supervisor. Select all employee SSNs in the database.

17 employee e, work_on w, project p, department d
Retrieve the salary of every employee. Retrieve all distinct salary values. Make a list of all project numbers for projects that involve an employee whose last name is 'Smith', either as a worker or as a manager of the department that controls the project. Retrieve all employees whose address is in Houston, Texas. Find all employees who were born during the 1950s. Show the resulting salaries if every employee working on the 'ProductX' project is given a 10 percent raise. Retrieve all salaries of employees in department 5 whose salary is between $30,000 and $40,000.

18 employee e, work_on w, project p, department d
Retrieve a list of employees and the projects they are working on, ordered by department and, within each department, ordered alphabetically by last name, then first name. Retrieve the names of all employees who do not have supervisors. Returns the names of employees whose salary is greater than the salary of all the employees in department 5. Retrieve the name of each employee who has a dependent with the same first name and is the same sex as the employee. Retrieve the names of employees who have no dependents.

19 employee e, work_on w, project p, department d
List the names of managers who have at least one dependent. Retrieve the Social Security numbers of all employees who work on project numbers 1, 2, or 3. Find the sum of the salaries of all employees, the maximum salary, the minimum salary, and the average salary. Find the sum of the salaries of all employees of the 'Research' department, as well as the maximum salary, the minimum salary, and the average salary in this department. Retrieve the total number of employees in the company.

20 employee e, work_on w, project p, department d
Retrieve the number of employees in the 'Research' department. Count the number of distinct salary values in the database. Retrieve the names of all employees who have two or more than one dependents. For each department, retrieve the department number, the number of employees in the department, and their average salary. For each project, retrieve the project number, the project name, and the number of employees who work on that project.

21 employee e, work_on w, project p, department d
For each project on which more than two employees work, retrieve the project number, the project name, and the number of employees who work on the project. For each project, retrieve the project number, the project name, and the number of employees from department 5 who work on the project. Count the total number of employees whose salaries exceed $40,000 in each department, but only for departments where more than five employees work.


Download ppt "COP Introduction to Database Structures"

Similar presentations


Ads by Google