160 likes | 271 Vues
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 16.19.
E N D
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 16.19 select distinct movietitle from starsIn a, (select name from moviestar where birthdate like '%1974%') temp where a.starname = temp.name; • RAE=Relational Algebra Expressible SQL
16.3Example16.19 Figure 16.24 πmovie title starname=name πname StarsIn σmovieYear lile ‘%1974’ MovieStar This is the RAE SQL
16.3. SQL/RAE of Figure 16.19 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 16.24 πmovie title starname=name starame, movie title πname σmovieYear lile ‘%1974%’ StarsIn MovieStar This is the RAE SQL
SQL in Figure 16.20 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 16.22 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;
πm1.movieYearm1.movieYear m1.movieYear -40 abd m2.movietitle=m1.movietitle and m2.movietitle=m1.movietitle γm2.movieTitle, m2.movieyear,AVG(birthDate)ave StarsIn m2,starname=s.name StaesIn MovieStar
πm1.movieYearm1.movieYear m1.movieYear -40 abd m2.movietitle=m1.movietitle and m2.movietitle=m1.movietitle πm1.movieYear,m1.movieYear γm2.movieTitle, m2.movieyear,AVG(birthDate)ave StarsIn m2,starname=s.name StaesIn MovieStar
πm1.movieYearm1.movieYear m1.movieYear -40 abd γm2.movieTitle, m2.movieyear,AVG(birthDate)ave m2,starname=s.name MovieStar StaesIn
πm1.movietitlem1.movieYear m1.movieYear -40 abd γm2.movieTitle, m2.movieyear,AVG(birthDate)ave m2,starname=s.name m1.movietitle m1.movieYear m1.movietitle m1.movieYear StaesIn MovieStar
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 ,SUM(qty) -->sum • • pname. qty • • (Natural join) π pnum,qty π pnum, pname Shipments Parts