16.3 Parser to Logical Query Plans
16.1. SQL(not RAE) Figure 16.2 select distinct movietitle from starsIn where starname in (select name from moviestar where birthdate like '%1974%'); NOTRAE=Relational Algebra NOT Expressible SQL
16.3. SQL/RAE of Figure select distinct movietitle from starsIn a, (select name from moviestar where birthdate like '%1996%') temp where a.starname = temp.name; RAE=Relational Algebra Expressible SQL
16.3Example16.19 Figure π movie title σ movieYear lile ‘%1996’ StarsIn This is the RAE SQL π name MovieStar starname=name
16.3. SQL/RAE of Figure select movietitle from (select starname,movietitle From starsIn) a, (select name from moviestar where birthdate like '%1974%') b where a.starname = b.name;
16.3Example16.19 Figure π movie title σ movieYear lile ‘%1974%’ StarsIn This is the RAE SQL π name MovieStar starname=name starame, movie title
SQL in Figure Select distinct m1.movieTitle, m1.movieYear From StarsIn m1 Where m1.movieYear – 40 <= ( Select AVG(birthdate) From StarsIn m2, Moviestar s Where m2.starName=s.name AND m1.movieTitle = m2.movieTitle AND m1.movieyear = m2.movieyear );
SQL in Figure Select distinct m.movieTitle, m.movieYear From StarsIn m1, ( Select m2.movieTitle, m2.movieyear, AVG(birthdate) as ave From StarsIn m2, Moviestar s Where m2.starName=s.name Group by m2.movieTitle, m2.movieyear ) m Where m1.movieTitle = m.movieTitle and m1.movieYear – 40 <=ave;
γ m2.movieTitle, m2.movieyear,AVG(birthDate) ave m2.movietitle=m1.movietitle and m2.movietitle=m1.movietitle m1.movieYear -40 abd π m1.movieYear m1.movieYear StarsIn m2,starname=s.name StaesIn MovieStar
γ m2.movieTitle, m2.movieyear,AVG(birthDate) ave m2.movietitle=m1.movietitle and m2.movietitle=m1.movietitle m1.movieYear -40 abd π m1.movieYear m1.movieYear StarsIn m2,starname=s.name StaesIn MovieStar π m1.movieYear,m1.movieYear
γ m2.movieTitle, m2.movieyear,AVG(birthDate) ave m1.movieYear -40 abd π m1.movieYear m1.movieYear m2,starname=s.name StaesIn MovieStar
γ m2.movieTitle, m2.movieyear,AVG(birthDate) ave m1.movieYear -40 abd π m1.movietitle m1.movieYear m2,starname=s.name StaesIn MovieStar m1.movietitle m1.movieYear
Lecture on Whiteboard Select PNAME, Sum (QTY) From Parts natural join Shipments Group by PNAME;
Lecture on Whiteboard pname,SUM(qty) -->sum (Natural Join) Shipments Parts pname,SUM(qty) -->sum (Shipment Parts)
Lecture on Whiteboard Select F.PNAME, Sum (F.QTY) as sum From ( Select PNAME, QTY FROM ( SELECT PNUM,PNAME From Parts) natural join ( Select PNUM, QTY From Shipments) )F Group by F.pname;
pname,MAX(qty) -->max pname. qty (Natural join) π pnum,qty π pnum, pname Shipments Parts