2010. 10. 21.  Employee (fname, minit, lname, ssn, bdate, address, sex, salary, superssn, dno)  Department (dname, dnumber, mgrssn, mgrstartdate) 

Slides:



Advertisements
Similar presentations
COMPANY schema EMPLOYEE
Advertisements

Lecture 1 Relational Algebra and Relational Calculus.
The Relational Algebra
Basic Queries. 2 Retrieval Queries in SQL SQL has one basic statement for retrieving information from a database; the SELECT statement This is not the.
SQL Query Slides Sharif University Of Technology Database Systems CE 384 Prepared By: Babak Bagheri Hariri
Your Logo Fundamentals of Database Systems Fourth Edition El Masri & Navathe Instructor: Mr. Ahmed Al Astal Chapter 8 (Cont.) SQL-99: Schema Definition,
Displaying Data from Multiple Tables. EMPNO DEPTNO LOC NEW YORK CHICAGO NEW YORK DALLAS
Database technology Lecture 2: Relational databases and SQL
Company Database. CREATE TABLE DEPARMENT ( DNAME VARCHAR(10) NOT NULL, DNUMBER INTEGER NOT NULL, MGRSSN CHAR(9), MGRSTARTDATE CHAR(9), PRIMARY KEY (DNUMBER),
LAB 4 FIGURES.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide 8- 1.
1 CSE 480: Database Systems Lecture 10: SQL - DML Reference: Read Chapter 4 of the textbook.
METU Department of Computer Eng Ceng 302 Introduction to DBMS SQL-99: Schema Definition, Basic Constraints, and Queries by Pinar Senkul resources: mostly.
Review Database Application Development Access Database Development ER-diagram Forms Reports Queries.
Database Systems Chapter 8 ITM 354. Data Definition, Constraints, and Schema Changes Used in SQL to Create, Drop, and Alter the descriptions of the tables.
More SQL: Complex Queries, Triggers, Views, and Schema Modification 1.
관계 연산자 & SQL. Selection SELECT * FROM r WHERE A=B AND D>5.
SQL The relational DB Standard CS-450 Dr. Ali Obaidi.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Chapter 8 SQL-99: SchemaDefinition, Constraints, and Queries and Views.
Chapter 3 MORE SQL Copyright © 2004 Pearson Education, Inc.
1 CS 430 Database Theory Winter 2005 Lecture 12: SQL DML - SELECT.
1 CSE 480: Database Systems Lecture 11: SQL. 2 SQL Query SELECT FROM WHERE –In MySQL, FROM and WHERE clauses are optional –Example:
SQL: Schema Definition, Constraints, & Queries and Views.
Relational Algebra - Chapter (7th ed )
CS 380 Introduction to Database Systems Chapter 7: The Relational Algebra and Relational Calculus.
Retrieve the names of all employees in department 5 who work more than 10 hours per week on the ‘ProductX’ project. p10ssn ← (Π essn (σ hours > 10 (works-on.
Database Management Systems. NESTING OF QUERIES  Some queries require that existing values in the database be retrieved and then used in a comparison.
Chapter 8 SQL- The Relational Database Standard 8-1.
Chapter 3 MORE SQL Copyright © 2004 Pearson Education, Inc.
莊裕澤資料庫基本概念 1 Yuh-Jzer Joung 莊 裕 澤 Dept. of Information Management National Taiwan University February, 2002 資料庫管理與資訊科技.
SQL Chapter 8. SQL or SEQUEL - (Structured English Query Language) Based on relational algebra Developed in 1970's released in early 1980's Standardized.
Chapter 8 Part 2 SQL-99 Schema Definition, Constraints, Queries, and Views.
1 CSE 480: Database Systems Lecture 12: SQL (Nested queries and Aggregate functions)
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Chapter 8 SQL-99: SchemaDefinition, Constraints, and Queries and Views.
Structured Query Language (2) The main reference of this presentation is the textbook and PPT from : Elmasri & Navathe, Fundamental of Database Systems,
DatabaseIM ISU1 Fundamentals of Database Systems Chapter 6 The Relational Algebra.
Chapter 11 SQL DML. Retrieval Queries in SQL SQL has one basic statement for retrieving information from a database; the SELECT statement This is not.
Announcements Written Homework 1 due Nov 2 –See course web page –Exercises 5.12, 5.15, 6.17, 6.20, 6.22 (a,c,f only). Today –continue with SQL (chapter.
Riyadh Philanthropic Society For Science Prince Sultan College For Woman Dept. of Computer & Information Sciences CS 340 Introduction to Database Systems.
Chapter SQL DML. Retrieval Queries in SQL SQL has one basic statement for retrieving information from a database; the SELECT statement This is not the.
1Fundamentals of Database Systems 기본키에 밑줄을 그은 COMPANY 관계 데이타베이스 스키마 FNAMEMINITLNAMESSNBDATEADDRESSSEXSALARYSUPERSSNDNO EMPLOYEE DNAMEDNUMBERMGRSSNMGRSTARTDATE.
COMP163 Database Management Systems September 18, 2008 Lecture 8 – Sections SQL Queries.
603 Database Systems Senior Lecturer: Laurie Webster II, M.S.S.E.,M.S.E.E., M.S.BME, Ph.D., P.E. Lecture 16 A First Course in Database Systems.
ISC321 Database Systems I Chapter 5: SQL: Advanced Queries, Assertions, Triggers, and Views Fall 2015 Dr. Abdullah Almutairi.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 4 Basic SQL تنبيه : شرائح العرض (Slides) هي وسيلة لتوضيح الدرس واداة.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 4 Basic SQL تنبيه : شرائح العرض (Slides) هي وسيلة لتوضيح الدرس واداة.
CS580 Advanced Database Topics Chapter 8 SQL Irena Pevac.
1 Chapter (8) SQL The Relational Database Standard Objectives Presenting the main features of SQL SQL is the Structured Query Language SQL commands SQL.
The SQL Database Grammar
CS580 Advanced Database Topics
SQL: SchemaDefinition, Constraints, and Queries and Views
Chapter 4 Basic SQL.
6/22/2018.
Retrieval Queries in SQL(DML)
Subject Name: DATA BASE MANAGEMENT SYSTEM Subject Code: 10cs54
376a. Database Design Dept. of Computer Science Vassar College
Mapping ER Diagrams to Tables
11/9/2018.
Joining Tables ضم الجداول وإستخراج مناظر views منها الهدف : 1- استخراج المعلومات من جدولين أو اكثر بالإستفادة من الرابط بينهما وبإستخدام SQL 2- شروط قواعد.
Company Requirements.
Session - 6 Sequence - 2 SQL: The Structured Query Language:
Chapter 4 & 5 Basic SQL More SQL
More SQL: Complex Queries, Triggers, Views, and Schema Modification
SQL-99: Schema Definition, Constraints, and Queries and Views
1. Explain the following concepts: (a) superkey (b) key
SQLPLUS: Oracle SQL Interface
SQL Grouping, Ordering & Arithmetics Presented by: Dr. Samir Tartir
SQL: Set Operations & Nested Queries. Presented by: Dr. Samir Tartir
Answers to Midterm - Exam. Feb. 27, 2006
Presentation transcript:

 Employee (fname, minit, lname, ssn, bdate, address, sex, salary, superssn, dno)  Department (dname, dnumber, mgrssn, mgrstartdate)  dept_locations (dnumber, dlocation)  Project (pname, pnumber, plocation, dnum)  works_on (essn, pno, hours)  Dependent (essn, dependent_name, sex, bdate, relationship)

 Retrieve the birthdate and address of the employee whose name is ‘ John B.Smith ’ SELECT bdate, address FROM employee WHERE fname = ‘John’ AND minit=‘B’ AND lname=‘Smith’

 Retrive the name and address of all employees who work for the ‘ Research ’ department SELECT fname, lname, address FROM employee, department WHERE dname=‘Research’ AND dnumber=dno

 For every project located in ‘ Stafford ’ list the project number, the controlling department number, and the department manager ’ s last name, address, and birthdate SELECT pnumber, dnum, lname, address, bdate FROM project, department, employee WHERE dnum-dnumber AND mgrssn=ssn AND plocation=‘Staffod’

 For each employee, retrieve the employee ’ s first and last name and the first and last name of his or her immediate supervisor SELECT e.fname, e.lname, s.fname, s.lname FROM employee e s WHERE e.superssn=s.ssn

 Make a list of all project numbers for projects that involve an employee whose last name is ‘ Smith ’ as a worker or as a manager of the department that controls the project (SELECT pnumber FROM project, department, employee WHERE dnum=dnumber AND mgrssn=ssn AND lname=‘Smith’) UNION (SELECT pnumber FROM project, works_on, employee WHERE pnumber=pno AND essn=ssn AND lname=‘Smith’)

 Retrieve the name of each employee who has a dependent with the same first name and same sex as the employee SELECT e.fname, e.lname FROM employee e WHERE e.ssn IN (SELECT essn FROM dependent WHERE essn=e.ssn AND e.fname=dependent_name AND sex=e.sex)

 Retrieve the names of employees who have no dependents SELECT fname, lname FROM employee WHERE NOT EXISTS (SELECT * FROM dependent WHERE ssn=essn)

 Retrieve the social security number of all employees who work on project number 1,2, or 3 SELECT DISTINCT essn FROM works_on WHERE pno IN (1,2,3)

 Retrieve the names of all employees who do not have supervisors SELECT fname, lname FROM employee WHERE superssn IS NULL

 Find the sum of the salaries of all employees, the maximum salary, the minimum salary, and the average salary SELECT SUM(salary), MAX(salary), MIN(salary) FROM employee

 Retrieve the total number of employees in the company and the number of employees in the ‘ Research ’ department SELECT COUNT(*) FROM employee SELECT COUNT(*) FROM employee, department WHERE dno=dnumber AND dname=‘Research’

 For each department, retrieve the department number,the number of employees in the department, and their average salary SELECT dno, COUNT(*), AVG(salary) FROM employee GROUP BY dno

 For each project on which more than two employees work retrieve the project number, project name, and number of employees who work on that project SELECT pnumber, pname, COUNT(*) FROM project, works_on WHERE pnumber=pno GROUP BY pnumber, pname HAVING COUNT(*) >2

 For each project, retrieve the project number, project name, and number of employees from department 5 who work on that project SELECT pnumber, pname, COUNT(*) FROM project, works_on, employee WHERE pnumber=pno AND ssn=essn AND dno=5 GROUP BY pnumber, pname

 Retrieve all employees who were born during the 1950s SELECT fname, lname FROM employee WHERE bdate LIKE ‘______5_’

 Find the salary lists to give all employees who work on the ‘ Product X ’ project a 10% raise SELECT fname, lname, 1,1*salary FROM employee, works_on, project WHERE ssn=essn AND pno=pnumber AND pname=‘ProductX’

 List ordered by the employee ’ s department and within each department ordered alphabetically by name SELECT dname, lname, fname, pname FROM department, employee, works_on, project WHERE dnumber=dno AND ssn=essn AND pno=pnumber ORDERED BY dname, lname, fname