COP Introduction to Database Structures

Slides:



Advertisements
Similar presentations
Exercise 2 Relational Calculus
Advertisements

SQL: Queries.
พีชคณิตแบบสัมพันธ์ (Relational Algebra) บทที่ 3 อ. ดร. ชุรี เตชะวุฒิ CS (204)321 ระบบฐานข้อมูล 1 (Database System I)
TURKISH STATISTICAL INSTITUTE 1 /34 SQL FUNDEMANTALS (Muscat, Oman)
1 Advanced SQL Queries. 2 Example Tables Used Reserves sidbidday /10/04 11/12/04 Sailors sidsnameratingage Dustin Lubber Rusty.
Chapter (7): Advanced SQL
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 SQL: Queries, Programming, Triggers Chapter 5 Modified by Donghui Zhang.
Conceptual Data Modeling: ER
COMPANY schema EMPLOYEE
Lecture 1 Relational Algebra and Relational Calculus.
Chapter 6 Additional Relational Operations Dr. Bernard Chen Ph.D. University of Central Arkansas Fall 2008.
SQL Query Slides Sharif University Of Technology Database Systems CE 384 Prepared By: Babak Bagheri Hariri
Schema BankWorld Customer(C_Name, C_Street, C_City) Depositor(Account_#, C_Name) Loan(Loan_#, B_Name, Amount) Borrower(C_Name, Loan_#)
CS 166: Database Management Systems
SQL (2).
CMPT 258 Database Systems SQL: Queries, Constraints, Triggers (Chapter 5) Part II home.manhattan.edu/~tina.tian.
Data Warehousing/Mining 1 Data Warehousing/Mining Comp 150 Aggregation in SQL (not in book) Instructor: Dan Hebert.
Employee database: Conceptual Schema in ERD Chapter 3, page 62.
FALL 2004CENG 351 File Structures and Data Management1 SQL: Structured Query Language Chapter 5.
CS 104 Introduction to Computer Science and Graphics Problems Introduction to Database (2) Basic SQL 12/05/2008 Yang Song.
Relational Algebra. Manipulating Databases To access information in a database we use a query Ex: How many customers have the first name = `John’? Good.
관계 연산자 & SQL. Selection SELECT * FROM r WHERE A=B AND D>5.
Relational algebra SHIRAJ MOHAMED M | MIS 1. Relational algebra Notation SHIRAJ MOHAMED M | MIS 2.
Al-Imam University Girls Education Center Collage of Computer Science 1 ST Semester, 1432/1433H Chapter 8 Part 4 SQL-99 Schema Definition, Constraints,
1 CSE 480: Database Systems Lecture 11: SQL. 2 SQL Query SELECT FROM WHERE –In MySQL, FROM and WHERE clauses are optional –Example:
Instructor: Jinze Liu Fall Basic Components (2) Relational Database Web-Interface Done before mid-term Must-Have Components (2) Security: access.
Structured Query Language. Group Functions What are group functions ? Group Functions Group functions operate on sets of rows to give one result per group.
SQL Examples CS3754 Class Note 11 CS3754 Class Note 11, John Shieh,
Database Management Systems,1 Relational Calculus.
Querying a Database - A question or an inquiry (dictionary.com) - WHAT ARE WE ASKING QUESTIONS ABOUT? THE DATA - BY ASKING QUESTIONS OF THE DATA WE OBTAIN?
 Employee (fname, minit, lname, ssn, bdate, address, sex, salary, superssn, dno)  Department (dname, dnumber, mgrssn, mgrstartdate) 
Database Management Systems. NESTING OF QUERIES  Some queries require that existing values in the database be retrieved and then used in a comparison.
CS 405G: Introduction to Database Systems Lecture 2 : Database Design I.
1 Database Systems ( 資料庫系統 ) October 24, 2005 Lecture #5.
Structured Query Language
Chapter 2 Data Modeling Using the Entity-Relationship (ER) Model Copyright © 2004 Pearson Education, Inc.
CMPT 258 Database Systems SQL Queries (Chapter 5).
Riyadh Philanthropic Society For Science Prince Sultan College For Woman Dept. of Computer & Information Sciences CS 340 Introduction to Database Systems.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Database Management Systems Chapter 5 SQL.
1 SQL: The Query Language (Part II). 2 Expressions and Strings v Illustrates use of arithmetic expressions and string pattern matching: Find triples (of.
CS 405G: Introduction to Database Systems Instructor: Jinze Liu Fall 2007.
CSCI 4333 Database Design and Implementation – Exercise (2) Xiang Lian The University of Texas Rio Grande Valley Edinburg, TX 78539
Database Management Systems 1 Raghu Ramakrishnan SQL: Queries, Programming, Triggers Chpt 5 Jianping Fan.
Example COMPANY Database
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 4 Basic SQL تنبيه : شرائح العرض (Slides) هي وسيلة لتوضيح الدرس واداة.
1 CS122A: Introduction to Data Management Lecture 9 SQL II: Nested Queries, Aggregation, Grouping Instructor: Chen Li.
SQL Exercises. 1) Names of suppliers. Suppliers(sid, sname, address) Parts(pid, pname, color) Catalog(sid, pid, cost)
CS580 Advanced Database Topics Chapter 8 SQL Irena Pevac.
Relational Calculus Database Management Systems, 3rd ed., Ramakrishnan and Gehrke, Chapter 4.
Relational Algebra Database Management Systems, 3rd ed., Ramakrishnan and Gehrke, Chapter 4.
CS580 Advanced Database Topics
COP Introduction to Database Structures
© פרופ' יהושע שגיב, האוניברסיטה העברית
01/31/11 SQL Examples Edited by John Shieh CS3754 Classnote #10.
Chapter 3 Introduction to SQL(3)
Database Systems October 14, 2009 Lecture #5.
Database Applications (15-415) SQL-Part II Lecture 9, February 04, 2018 Mohammad Hammoud.
RELATIONAL ALGEBRA (Chapter 2)
Database Systems 10/13/2010 Lecture #4.
Session - 6 Sequence - 2 SQL: The Structured Query Language:
CSCI 6315 Applied Database Systems – Exercise (3)
LECTURE 3: Relational Algebra
Entity-Relationship Modeling "Extended"
CS4222 Principles of Database System
SQL: Structured Query Language
Textbook Chapter 9 (incl. example queries at end)
SQL Grouping, Ordering & Arithmetics Presented by: Dr. Samir Tartir
Entity-Relationship Modeling "Extended"
Entity-Relationship Modeling "Extended"
CS 405G: Introduction to Database Systems
Presentation transcript:

COP 3540 - Introduction to Database Structures SQL II

Relations sailors

Relations boats reserves

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.

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.

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.

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.

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.

Relations

Relations

Relations

Relations

Relations

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.

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.

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.

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.

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.

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.