INSTALLMENT NUMBER 21 Relational Comparisons

Slides:



Advertisements
Similar presentations
Warm Up Example 1 Check whether the ordered pair is a solution of 2x – 3y > -2 a.(0,0) 2(0)-3(0)> -2 0> -2 True b.(0,1) 2(0)-3(1)> -2 -3> -2 False.
Advertisements

SQL: The Query Language Part 2
พีชคณิตแบบสัมพันธ์ (Relational Algebra) บทที่ 3 อ. ดร. ชุรี เตชะวุฒิ CS (204)321 ระบบฐานข้อมูล 1 (Database System I)
Copyright © C. J. Date 2005page 97 S#Y S1DURINGS3DURING [d04:d10][d08:d10] S2DURINGS4DURING [d02:d04][d04:d10] [d08:d10] WITH ( EXTEND T2 ADD ( COLLAPSE.
Relational Algebra, Join and QBE Yong Choi School of Business CSUB, Bakersfield.
Lecture 8 Logical Operations Logical functions & Relational operators © 2007 Daniel Valentine. All rights reserved. Published by Elsevier.
Relational Algebra Relational Calculus. Relational Algebra Operators Relational algebra defines the theoretical way of manipulating table contents using.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 6 The Relational Algebra and Relational Calculus.
Domains, Relations & Base RelVars (Ch
1 Relational Algebra and Calculus Yanlei Diao UMass Amherst Feb 1, 2007 Slides Courtesy of R. Ramakrishnan and J. Gehrke.
Relational Algebra Chapter 4 - part I. 2 Relational Query Languages  Query languages: Allow manipulation and retrieval of data from a database.  Relational.
CSCD343- Introduction to databases- A. Vaisman1 Relational Algebra.
Relational Algebra.
Chapter 6 Relations. Copyright © 2004 Pearson Addison-Wesley. All rights reserved.6-2 Topics in this Chapter Tuples Relation Types Relation Values Relation.
Bell Work: Given the sets L = {0, 1, 2, 3}, M = {5, 6, 7}, and N = {0, 1}, are the following statements true or false? (a) 6 L (b) 0 N.
Chapter 6 Relations. Topics in this Chapter Tuples Relation Types Relation Values Relation Variables SQL Facilities.
Relational Algebra II. Semantics - where A WHERE X  Y –  : an operator like =, >, … Result of restriction A by the condition X  Y is A relation –with.
Advanced SQL Murat Kantarcioglu Adapted from Silberchatz et al. slides.
Chapter 4.1 Solving Systems of Linear Equations in two variables.
Objectives Define and use imaginary and complex numbers.
Chapter 8 Relational Calculus. Copyright © 2004 Pearson Addison-Wesley. All rights reserved.8-2 Topics in this Chapter Tuple Calculus Calculus vs. Algebra.
CSE314 Database Systems The Relational Algebra and Relational Calculus Doç. Dr. Mehmet Göktürk src: Elmasri & Navanthe 6E Pearson Ed Slide Set.
Chapter 7 Relational Algebra. Topics in this Chapter Closure Revisited The Original Algebra: Syntax and Semantics What is the Algebra For? Further Points.
Standard: M11.D Algebra 3 Lesson 4.1
Bayu Adhi Tama, ST., MTI. Introduction Relational algebra and relational calculus are formal languages associated with the relational.
Yufis Azhar – Teknik Informatika – UMM.  Aggregation function takes a collection of values (of a single attribute) and returns a single value as a result.
Chapter 7 Relational Algebra. Copyright © 2004 Pearson Addison-Wesley. All rights reserved.7-2 Topics in this Chapter Closure Revisited The Original Algebra:
1 Relational Algebra and Calculas Chapter 4, Part A.
1.1 CAS CS 460/660 Introduction to Database Systems Relational Algebra.
Copyright © 2014 Curt Hill Sets Introduction to Set Theory.
Chapter 5 Relational Algebra and Relational Calculus Pearson Education © 2009.
Chapter 5 Relational Algebra Pearson Education © 2014.
CSCD34-Data Management Systems - A. Vaisman1 Relational Algebra.
1 Algebra of Queries Classical Relational Algebra It is a collection of operations on relations. Each operation takes one or two relations as its operand(s)
Installment Numbers 6 Answers to Puzzle Corner Problems (Installment Numbers1-5) 會研所 黃潔.
Section P.7  An expression is an algebraic statement that does not have an “=“  An equation is two expressions joined by an “=“
1 CS 430 Database Theory Winter 2005 Lecture 5: Relational Algebra.
INSTALL NUMBER 12 Answers to Puzzle Corner Problems (Installment Number 7-11) 中正大學資管所 碩一 郭 溥 淵.
Lu Chaojun, SJTU 1 Extended Relational Algebra. Bag Semantics A relation (in SQL, at least) is really a bag (or multiset). –It may contain the same tuple.
Integrity Prof. Yin-Fu Huang CSIE, NYUST Chapter 9.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Relational Algebra Chapter 4, Part A.
Installment 17 Toil and Trouble 資管所 研一 涂延坤.
Chapter 8 Relational Calculus.
CSE202 Database Management Systems
STRUCTURE OF PRESENTATION :
More SQL: Complex Queries,
Chapter 10 Views.
CS4432: Database Systems II
Linear Equations in One Variable
STRUCTURE OF PRESENTATION :
STRUCTURE OF PRESENTATION :
Chapter 3: Relational Model III
Chapter 8 Relational Calculus.
COMP 430 Intro. to Database Systems
SQL Structured Query Language 11/9/2018 Introduction to Databases.
Relational Algebra 461 The slides for this text are organized into chapters. This lecture covers relational algebra, from Chapter 4. The relational calculus.
Relational Algebra.
Relational Operators Operator Meaning < Less than > Greater than
More SQL: Complex Queries, Triggers, Views, and Schema Modification
Advanced Database System
Equations and Inequalities
TRUTH TABLES.
The Relational Algebra
The Relational Algebra
STRUCTURE OF PRESENTATION :
AP Statistics Warm-up: Problem 5.26.
Shelly Cashman: Microsoft Access 2016
SQL: The Query Language (Part III)
Presentation transcript:

INSTALLMENT NUMBER 21 Relational Comparisons 資管所 碩一 林思元 2001,12

Relational Comparisons THE BASIC IDEA NEW CONDITIONAL EXPRESSIONS SOME RESTRICTION EXAMPLES SOME MORE SHORTHANDS ADDITIONAL BENEFITS CONCLUDING REMARKS

THE BASIC IDEA What does it mean to assign one object of this type to another? int a = 3 ; int b = 5 ; What does it mean to compare two objects of this type? a  b

THE BASIC IDEA What new comparison operators we need? we need the things like “equals”, “subset of”, “proper subset of”, “superset of”, “proper superset of”

THE BASIC IDEA Define a new kind of conditional or truth-valued expression that incorporates those comparison operators (Orthogonality!)Permit those conditional expressions to be used wherever conditional expressions are currently permitted

NEW CONDITIONAL EXPRESSIONS rel-exp-1 rel-θ rel-exp-2 rel-θ is any of the following comparison operators:  (equals)  (not equals)  (subset of)  (proper subset of)  (superset of)  (proper superset of)

NEW CONDITIONAL EXPRESSIONS the negation of “A is a proper subset of B” is certainly not “A is a superset of B” ( “” and “” are not inverses of each other) A = {1,2} B = {3,4}

NEW CONDITIONAL EXPRESSIONS 1. S [ CITY ]  P [ CITY ] Is the projection of suppliers(S) over CITY the same as the projection of parts(P) over CITY? 2. S [ S#]  SP [ S# ] Are there any suppliers who don’t supply any parts?

SOME RESTRICTION EXAMPLES Example 1:Find suppliers who supply all parts ( SP [ S#, P# ] DIVIDEBY P [ P# ] ) JOIN S

SOME RESTRICTION EXAMPLES   SP P ÷  S JOIN  S# P# 1 A B 2 3 P# A B S# 1 S# …. 1 2 3 S# 1 S# …. 1    

SOME RESTRICTION EXAMPLES T : SP RENAME S# AS X ; ANS : S WHERE ( T WHERE X  S# ) [ P# ]  P [ P# ] ; SP T S# P# …. 1 A B 2 3 X P# …. 1 A B 2 3

SOME RESTRICTION EXAMPLES ANS : S WHERE ( T WHERE X  S# ) [ P# ]  P [ P# ] ; S S# …. 1 2 3 P# A B ? = P# A B S# …. 1 只有 1 為 true 1 T 2 X P# …. 1 A B 2 3 3

SOME RESTRICTION EXAMPLES S WHERE ( ( SP RENAME S# AS X ) WHERE X  S# ) [ P# ]  P [ P# ] ( MATCHING rel-exp ) [ cols] S WHERE ( MATCHING SP ) [ P# ]  P [ P# ]

SOME RESTRICTION EXAMPLES S J SP PJ S# …. 1 2 J# …. 1 2 S# P# …. 1 2 J# P# …. 1 2

SOME RESTRICTION EXAMPLES ( ( S TIMES J ) WHERE ( MATCHING SP ) [ P# ]  ( MATCHING PJ ) [ P# ] ) [ S#, J# ] a relation with heading {S#,J#} such that supplier S# supplies all parts used in project J#

SOME RESTRICTION EXAMPLES ( ( S TIMES J ) WHERE ( MATCHING SP ) [ P# ]  ( MATCHING PJ ) [ P# ] ) [ S#, J# ] S# J# …. 1 2 S  J

SOME RESTRICTION EXAMPLES ( ( S TIMES J ) WHERE ( MATCHING SP ) [ P# ]  ( MATCHING PJ ) [ P# ] ) [ S#, J# ] S  J SP PJ S# J# …. 1 2 S# P# …. 1 2 J# P# …. 1 2

SOME RESTRICTION EXAMPLES 1 2 S# J# 1 P# 2 true ?  P# 1 2 P# 1 2 ?  true S# J# 1 2 P# 1 P# 2 ?  false P# 1 2 P# 1 ?  false

SOME RESTRICTION EXAMPLES ( ( S TIMES J ) WHERE ( MATCHING SP ) [ P# ]  ( MATCHING PJ ) [ P# ] ) [ S#, J# ] a relation with heading {J#,S#} such that project J# uses all parts supplied by supplier S#

SOME RESTRICTION EXAMPLES 1 2 P# 2 false ?  P# 1 2 P# 1 2 ?  false P# 1 P# 2 ?  false P# 1 2 P# 1 S# J# 2 ?  true

SOME RESTRICTION EXAMPLES Example 3:the pairs-of-suppliers problem Given relation SP { S#,P# } showing which suppliers (S#) supply which parts (P#), give (a) an SQL solution, (b) a relational algebra solution, to the problem of finding all pairs of supplier numbers, Sx and Sy say, such that Sx and Sy supply exactly the same set of parts each.

SOME RESTRICTION EXAMPLES Example 3:the pairs-of-suppliers problem ( RX TIMES RY ) WHERE ( SP WHERE S#  SX ) [ P# ]  ( SP WHERE S#  SY ) [ P# ] Appending an additional condition “AND SX  SY” would produce a slightly tidier result; specifically, it would (a) eliminate pairs of the form (Sx, Sx), and (b)ensure that the pairs (Sx,Sy) and (Sy,Sx) do not both appear.

SOME MORE SHORTHANDS whether the given relation contain zero rows IS_EMPTY ( rel-exp ) whether a given row r appear within a given relation R {r}  R r IN R

ADDITIONAL BENEFITS We wouldn’t need the quantifiers! - using relational comparisons EXISTS X ( P )  NOT ( IS_EMPTY ( X WHERE P ) ) FORALL X ( P )  IS_EMPTY ( X WHERE NOT ( P ) )

ADDITIONAL BENEFITS We wouldn’t need the quantifiers! - using aggregate function COUNT EXISTS X ( P )  COUNT ( X WHERE P )  0 FORALL X ( P )  COUNT ( X WHERE P )  COUNT ( X )

CONCLUDING REMARKS The idea of relational comparisons is not new. However, I’m not aware of any implementation of the relational algebra per se that includes support for such comparisons.

CONCLUDING REMARKS Puzzle corner problem: Find suppliers who supply at least all parts supplied by supplier S2. Find supplier numbers for suppliers who supply at least all parts supplied by at least one supplier who supplies at least one London part.

CONCLUDING REMARKS Puzzle corner problem: Find suppliers who supply at least all parts supplied by supplier S2. S WHERE ( MATCHING SP ) [ P# ]  ( SP WHERE S#  ‘S2’) [ P# ]

CONCLUDING REMARKS Puzzle corner problem: Find supplier numbers for suppliers who supply at least all parts supplied by at least one supplier who supplies at least one London part. ( SP WHERE P# IN ( SP WHERE S# IN ( P WHERE CITY  ‘London’) [ P# ] ) [ S# ] ) [ P# ] ) [ S# ]

THE END ~