Presentation is loading. Please wait.

Presentation is loading. Please wait.

Relational Query Operators (ii). Other Joins Theta join: Apply any specified condition on the product of two relations. Example: BoyStudent: BID, Bname,

Similar presentations


Presentation on theme: "Relational Query Operators (ii). Other Joins Theta join: Apply any specified condition on the product of two relations. Example: BoyStudent: BID, Bname,"— Presentation transcript:

1 Relational Query Operators (ii)

2 Other Joins Theta join: Apply any specified condition on the product of two relations. Example: BoyStudent: BID, Bname, GPA GirlStudent: GID, Gname, GPA Boys want to date with girls who have better GPA.

3 Outer Join Records in a relation that do not have matching values are included in the result relation. Missing values are set to null.

4 Outer Join Exmple Product Table: –PIDPname –P1TV –P2VCR –P3Computer –P4Tape –P5DVD TotalSales –PIDTotalSales –P150 –P360 –P540 Product Join TotalSales Product OuterJoin Totalsales PID Pname TotalSales P1TV50 P2VCR P3Computer 60 P4Tape P5DVD40

5 Branch: BIDCity B1SF B2SM B3SJ Full Outer Join: BIDCityPID B1SFP3 B2SMNull B3SJP2 NullLAP1 Right Outer Join: BIDCityPID B1SFP3 B3SJP2 NullLAP1 Property: PIDCity P1LA P2SJ P3SF Left Outer Join: BIDCityPID B1SFP3 B2SMNull B3SJP2

6 How to Implement Join Outer – Inner loop Sort – Merge Index on the join attributes –Faculty Join Student

7 Division Assume relation R is defined over the attribute set A and relation S is defined over the attribute set B where B is a subset of A. Let C = A – B, then the division operation defines a relation over the attribute C that consists of the set of records from R that match the combination of every records in S.

8 Division Example Relation R: –AB –ax –ay –az –bx –cz Relation S: B x z R ÷ S: A a

9 ApplicantPositionSkill ApplicantSkillPositionSkill AIDSIDPIDSID A1S1P1S1 A1S2P1S2 A2S2P2S1 A3S1P3S2 A4S1 A4S2 A4S3 Query: Find applicants that meet the skills required by position P1.

10 Aggregate Functions Max, Min, Sum, Count, Avg Ex. Student: SID,Sname, GPA, Sex, Major –F count(SID) (Student) –F avg(GPA) (Student) –F count(SID), avg(GPA) (Student)

11 Aggregates by Group Sex F count(SID) (Student) Major F count(SID) (Student) Major, Sex F count(SID) (Student) GPA F count(SID) (Student) ? Grouping field: –EmpID, Ename, DOB, Salary, Gender, Race

12 Examples Student: SID,Sname, GPA, Sex, Major StudentCourse: SID, CID Course: CID, Cname, Credits Queries: –Number of students in each major In each sex group In major, sex group –Number of students in each course CID, CName, NumbeOfStudents –Total credits for each student: SID, Sname, TotalCredits


Download ppt "Relational Query Operators (ii). Other Joins Theta join: Apply any specified condition on the product of two relations. Example: BoyStudent: BID, Bname,"

Similar presentations


Ads by Google