Branch (Bno, Street, Area, City, Pcode, Tel_No, Fax_NO) Staff (Sno, FName, LName, Address, Tel_No, Position, Sex, DOB, Salary, NIN, Bno) Property_for_Rent.

Slides:



Advertisements
Similar presentations
SQL. More than 100 DBMS support SQL –Used by DBAs and application programmers –Structured Query Language or SEQUEL –ORACLE-> relation database based on.
Advertisements

RELATIONAL DATABASES. Relational data Structure RELATION: Table with columns and rows ATTRIBUTE: Column of a relation DOMAIN: Set of allowable values.
Assignment Design Methodology A structured approach that uses procedures, techniques, tools, and documentation aids to support and facilitate the.
COMPANY schema EMPLOYEE
CSC271 Database Systems Lecture # 11.
RELATIONAL ALGEBRA Lecture Relational Algebra Operations to manipulate relations. Used to specify retrieval requests (queries). Query results in.
CSC271 Database Systems Lecture # 13. Summary: Previous Lecture  Grouping through GROUP BY clause  Restricted groupings  Subqueries  Multi-Table queries.
1 Design Methodology A structured approach that uses procedures, techniques, tools, and documentation aids to support and facilitate the process of design.
1 CS 3630 Database Design and Implementation. 2 Final Exam 7:00 – 8:52 PM, Thursday, May 16 Section 1: Ull 009 Section 2: Ull Points –50 points.
Chapter 5 SQL. Agenda Data Manipulation Language (DML) –SELECT –Union compatible operations –Update database.
관계 연산자 & SQL. Selection SELECT * FROM r WHERE A=B AND D>5.
Relational Database Management System A type of database in which records are stored in relational form is called relational database management system.
Chapter 6 SQL. Agenda Data Definition Language (DDL) Access Control.
Your Oracle Account UserName is the same as your UWP username Followed Not case sensitive Initial Password: UWPstudent Password is case sensitive.
Introduction to Databases. Case Example: File based Processing Real Estate Agent’s office Property for sale or rent Potential Buyer/renter Staff/employees.
Chapter 6 SQL Data Definition Language Chapter 7 in Textbook.
Agenda TMA01 M876 Block 3 – Using SQL Structured Query Language - SQL A non-procedural language to –Create database and relation structures. –Perform.
SQL: Overview SQL Overview © Pearson Education Limited 1995, 2005.
CSC271 Database Systems Lecture # 12. Summary: Previous Lecture  Row selection using WHERE clause  WHERE clause and search conditions  Sorting results.
Chapter 7 SQL: Data Manipulation Chapter#6 in the text book Pearson Education © 2009.
SQL Data Manipulation II Chapter 5 CIS 458 Sungchul Hong.
1 General Form of the SELECT Statement SELECT [DISTINCT | ALL {* | col_expr [AS new_name] [,…]} FROMtable_name [,…] [,…] [WHERE condition] [GROUP BY col_list]
Chapter 5 SQL Data Manipulation Language Chapter 5 in Textbook.
Chapter 5 SQL: Data Manipulation © Pearson Education Limited 1995, 2005.
Bayu Adhi Tama, ST., MTI. Introduction Relational algebra and relational calculus are formal languages associated with the relational.
Advanced Database Systems
 Employee (fname, minit, lname, ssn, bdate, address, sex, salary, superssn, dno)  Department (dname, dnumber, mgrssn, mgrstartdate) 
CS 3630 Database Design and Implementation. 2 DreamHome Branch (branchNo, street, city, state, zipcode, phone1, phone2, phone3) Staff (staffNo, firstName,
1 Pertemuan > > Matakuliah: >/ > Tahun: > Versi: >
1 E-R Model (II) Keys To identify records in a table Candidate Key Primary Key Alternate Key Composite Key.
Chapter 7 SQL: Data Manipulation Chapter #6 in the textbook Pearson Education © 2009.
CS 3630 Database Design and Implementation. 2 Functions y = f(x) x1 = x2  f(x1) = f(x2) Same x value, then same function value. Yes, it’s a function!
CS 3630 Database Design and Implementation. Database Schema Branch (Bno…) Staff (Sno…Bno) Owner (Ono…) PropertyForRent (Pno…Ono) Renter (Rno…) Viewing.
Chapter 5 Relational Algebra and Relational Calculus Pearson Education © 2009.
IST 210 SQL Todd Bacastow IST 210: Organization of Data.
Chapter 8 Introduction to SQL
Chapter 5 Relational Algebra Pearson Education © 2014.
Chapter 18 Query Processing. 2 Chapter - Objectives u Objectives of query processing and optimization. u Static versus dynamic query optimization. u How.
1 Geog 357 – Introduction to GIS The Relational Language.
CSC271 Database Systems Lecture # 8. Summary: Previous Lecture  Relation algebra and operations  Selection (Restriction), projection  Union, set difference,
Schema Conversion Create a table for each entity –1:1 choose one side and put a foreign key –1:* put a foreign key in many side –*:* create a table for.
Chapter 4 Practice Problem Solutions. A list (Bno, Street, Area,Tel_No, Fax_No) of branches located in Bay Area Branch (Bno, Street, Area, City, Pcode,
Branch (Bno, Area, City, Pcode) Staff (Sno, FName, LName, Position, Sex, DOB, Salary, Bno) Property_for Rent (Pno, Area, City, Type, Rooms, Rent, Ono,
Data Definition Language
2 Database Design Chapter Operations of the Relational Model Updates: changes the database’s state. Insert Delete Update/modify Retrievals: does.
Quiz Where to Store Attributes of Relationship Staff (1) Interviews (0..*) Client Attributes: date, time, comment Staff (StaffNo, …) PK: StaffNo.
IST 210 More SQL Todd Bacastow IST 210: Organization of Data.
SQL: Additional Notes. 2 Example 5.3 Use of DISTINCT List the property numbers of all properties that have been viewed. SELECT propertyNo FROM Viewing;
Teacher Workshop Database Design Pearson Education © 2014.
Chapter 11 SQL: Data Manipulation
Relational Algebra Lecture 2.
CS 3630 Database Design and Implementation
CS 3630 Database Design and Implementation
6/22/2018.
Data Manipulation Language
CS 3630 Database Design and Implementation
CS311 Database Management system
Working with Tables: Join, Functions and Grouping
The Relational Database Model
Chapter Name SQL: Data Manipulation Chapter #6 in the textbook
Chapter Name SQL: Data Manipulation Chapter #6 in the textbook
Chapter Name SQL: Data Manipulation
Quiz 1 1. Given two sets S = {3, 5, 7} and T = {2, 4, 6}. List all elements of the following set: {(s, t) | (s, t)  S  T and s + t = 9} Result (3, 6)
CS 3630 Database Design and Implementation
SQL – Data Manipulation
Chapter Name SQL: Data Manipulation
SQLPLUS: Oracle SQL Interface
Aggregate functions Objective- understand and able to use aggregate functions in select statement Aggregate functions are used to implement calculation.
SQL Grouping, Ordering & Arithmetics Presented by: Dr. Samir Tartir
Chapter Name SQL: Data Manipulation
Presentation transcript:

Branch (Bno, Street, Area, City, Pcode, Tel_No, Fax_NO) Staff (Sno, FName, LName, Address, Tel_No, Position, Sex, DOB, Salary, NIN, Bno) Property_for_Rent (Pno, Street, Area, City, Pcode, Type, Rooms, Rent, Ono, Sno, Bno) Renter (Rno, Fname, Lname, Address, Tel_NO, Pref_Type, Max_Rent) Owner ( Ono, Fname, LName, Address, Tel_No) Viewing (Rno, Pno, Date, Comment)

A list (Bno, Street, Area, Tel_No, Fax_No) of branches located in Bay Area SELECT (Bno, Street, Tel_No, Fax_No) FROM Branch WHERE Area = ‘Bay’;

A list (Pno, Street, Area, City) of properties for rent with 4 bedrooms or less than $1,000 per month rent SELECT (Pno, Street, Area, City) FROM Property_for_rent WHERE Rooms = 4 OR Rent < 1000;

A list (Sno, FName, LName) of female mangers with salary between one to two million dollars SELECT (Sno, FName, LName) FROM Staff WHERE Position = ‘manager’ AND Sex = ‘f’ AND Salary BETWEEN AND ;

A list (Pno, Street, Area, City) of properties for rent located in SF, LA, NY, or DC SELECT (Pno, Street, Area, City) FROM Property_for_rent WHERE City IN (‘SF’, ‘LA’, ‘NY’, ‘DC’);

A list (Pno, Street, Area, City) of properties for rent not located in SF, LA, NY, or DC SELECT (Pno, Street, Area, City) FROM Property_for_rent WHERE City NOT IN (‘SF’, ‘LA’, ‘NY’, ‘DC’);

A list (Ono, Fname, Lname) of owners without any telephone SELECT (Ono, Fname, Lname) FROM Owner WHERE Tel_No IS NULL;

The total number of branches SELECT COUNT(Bno) FROM Branch; SELECT COUNT(*) FROM Branch;

The total number of staffs SELECT COUNT(Sno) FROM Staff; SELECT COUNT(*) FROM Staff;

The total salary of male managers SELECT SUM(Salary) FROM Staff WHERE Sex = ‘m’ AND Position = ‘manager’;

The minimum salary of the female manager SELECT MIN(Salary) FROM Staff WHERE Sex = ‘f’ AND Position = ‘manager’;

The maximum rent to rent a property SELECT MAX(Rent) FROM Property_for_rent;

The average salary of male staff members SELECT AVG(Salary) FROM Staff WHERE Sex = ‘m’;

The average number of rooms in the single house type SELECT AVG(Rooms) FROM Property_for_rent WHERE Type = ‘single house’;

The number of employee in each branch SELECT Bno, COUNT(Sno) FROM Staff GROUP BY Bno; SELECT Bno, COUNT(Sno) FROM Branch b, Staff s WHERE b.Bno=s.Bno GROUP BY Bno;

The average salary of each branch SELECT Bno, AVG(Salary) FROM Staff GROUP BY Bno;

The average salary in each branch with more than 10 staff members SELECT Bno, AVG(Salary) FROM Staff GROUP BY Bno HAVING COUNT(*) > 10;

The number of employee in each branch located in SF, NY, LA, and DC SELECT City, Bno, COUNT(Sno) FROM Staff s, Branch b WHERE s.Bno = b.Bno AND City IN (‘SF’, ‘LA’, ‘NY’, ‘DC’) GROUP BY (City, Bno);

The number of employees in each branch with more than 10 employees and located in SF, NY, LA, and DC SELECT City, Bno, COUNT(Sno) FROM Branch b, Staff s WHERE b.Bno = s.Bno AND City IN (‘SF’, ‘NY’, ‘LA’, ‘DC’) GROUP BY (City, Bno) HAVING COUNT(*) > 10;

A list (Pno, Street, Area, City) of properties for rent managed by John Dow and owned by Sue Lee SELECT (Pno, Street, Area, City) FROM Property_for_rent p, Owner o, Staff s WHERE p.Ono = o.Ono AND s.Sno = p.Sno AND (s.FName = ‘John’ AND s.LName = ‘Dow’) AND (o.FName = ‘Sue’ AND o.LName = ‘Lee’);

A list (Sno, FName, LName) of staff without managing any property for rent SELECT (Sno, FName, LName) FROM Staff WHERE Sno NOT IN (SELECT Sno FROM Property_for_rent);

A list (Sno, FName, LName) of staffs without managing any property for rent SELECT (Sno, FName, LName) FROM Staff s WHERE NOT EXIST (SELECT * FROM Property_for_rent p WHERE p.Sno = s.Sno);

A list (Sno, FName, LName) of staffs without managing any property for rent SELECT (Sno, FName, LName) FROM Staff s LEFT JOIN Property_for_rent p ON s.Sno = p.Sno WHERE Pno IS NULL;

A list (Rno, Fname, Lname) of renters without looking any property for rent SELECT (Rno, FName, LName) FROM Renter WHERE Rno NOT IN (SELECT Rno FROM Viewing);

A list (Rno, Fname, Lname) of renters without looking any property for rent SELECT (Rno, FName, LName) FROM Renter r WHERE NOT EXIST (SELECT * FROM Viewing v WHERE r.Rno = v.Rno);

A list (Rno, Fname, Lname) of renters without looking any property for rent SELECT (Rno, FName, LName) FROM Renter r LEFT JOIN Viewing v ON r.Rno = v.Rno WHERE Pno IS NULL;

A list (Pno, Street, Area, City) of property for rent without any viewing SELECT (Pno, Street, Area, City) FROM Property_for_rent WHERE Pno NOT IN (SELECT Pno FROM Viewing);

A list (Pno, Street, Area, City) of property for rent without any viewing SELECT (Pno, Street, Area, City) FROM Property_for_rent p WHERE NOT EXIST (SELECT * FROM Viewing v WHERE p.Pno = v.Pno);

A list (Pno, Street, Area, City) of property for rent without any viewing SELECT (Pno, Street, Area, City) FROM Property_for_rent p LEFT JOIN Viewing v ON p.Pno = v.Pno WHERE v.Pno IS NULL;

A list (Sno, FName, LName) of staff managing a property for rent SELECT Distinct(Sno, FName, LName) FROM Staff s JOIN Property_for_rent p ON s.Sno = p.Sno; SELECT Distinct(Sno, FName, LName) FROM Staff s, Property_for_rent p WHERE s.Sno = p.Sno;

A list (Rno, Fname, Lname) of viewing renter SELECT (Rno, FName, LName) FROM Renter r JOIN Viewing v ON r.Rno = v.Rno; SELECT (Rno, FName, LName) FROM Renter r, Viewing v WHERE r.Rno = v.Rno;

A list (Sno, FName, LName) of the highest salary staff SELECT (Sno, FName, LName) FROM Staff s WHERE Salary = (SELECT MAX(Salary) FROM Staff);

What is the most common property for rent type for all branches? What is the type of property that has been viewed the most by renters? Name the staff no and his/her branch no managing the most property.

What is the most common property for rent type for all branches? Select Type (Select Type, Max(X) (Select Type, Count(*) As X From Property_For_Rent Group by Type) Group by Type);

What is the type of property that has been viewed the most by renter? Select Type (Select Type, Max(X) (Select Type, Count(*) As X From Property_For_Rent p, Viewing v Where p.Pno = v.Pno Group by Type) Group by Type);

Name the staff no and his/her branch no managing the most property. Select Bno, Sno From (Select Bno, Sno, Max(X) (Select Bno, Sno, Count(*) As X From Property_For_Rent Group by Bno, Sno) Group by Bno, Sno);