340 likes | 393 Views
CSC 3810 Lecture Slides Relational Algebra. Instance S1 of Stations. network = “NBC” (S1) . What stations are in the NBC network?. network, town (S1) . What networks in what towns are represented?. network (S1) . What networks are represented?.
E N D
network = “NBC” (S1) What stations are in the NBC network?
network, town (S1) What networks in what towns are represented?
network (S1) What networks are represented?
channel, town(network = “ABC” (S1)) What channels are ABC in what towns?
Instance P1 of Programs Programs ( statid:integer, showid:integer, timeslot:integer,day:string )
Instance T1 of TVShows TVShows ( showid:integer, title:string )
P1⋈P1.showid=T1.showid T1.title=”West Wing” T1 When is the West Wing on?
S1 ⋈ S1.statid = P1.statid P1 When is each station showing something?
(S1 ⋈ P1) ⋈ T1 What shows are being shown on which stations, when?
Instance D1 of DVDs DVDs (did: integer, title: string)
Instance P1 of People People (pid: integer, name: string)
Instance O1 of Owns Owns (pid: integer, did: integer)
O1 ⋈ D1 Who owns which DVD? (first try)
O1 ⋈ D1 ⋈ P1 Who owns which DVD? (with names this time)
name,title (O1 ⋈ D1 ⋈ P1) Who owns which DVD?
title=“The Matrix”(name,title(O1 ⋈ D1 ⋈ P1)) Who owns “The Matrix?”
name=“Bob”(name,title(O1 ⋈ D1 ⋈ P1)) Which movies does Bob own?
name=“Ellen” (O2) name=“Mary” (O2) Ellen and Mary have combined their movie collection. What is in their joint collection?
name=“Ellen” (O2) name=“Mary” (O2) Which movies do they have duplicates of?
pid (title=“The Matrix” (D1) ⋈ O1) Who owns “The Matrix?” Name this “MatrixOwners”
pid (title=“Star Wars” (D1) ⋈ O1) Who owns “Star Wars?” Name this “StarWarsOwners”
name (MatrixOwners StarWarsOwners ) ⋈ P1) Who owns both “The Matrix” and “Star Wars?”
ρ(Ownership, pid,.name,did (O1⋈P1)) Who owns which movies? Name this “Ownership”
ρ( Pairs (1→pid1, 2→name1, 3→did1, 4 → pid2, 5→name2, 6→did2), Ownership Ownership ) What are all pairs of owned movies?
name1 (pid1=pid2 did1did2( Pairs ) ) Who owns at least two movies?
Division Who are the people in O1 (left) where for every did in D1 (below), there is a tuple in O1? I.e., who owns every movie?
Division pid (O1) did (D1) ( pid (O1) did (D1) ) – O1 pid (( pid (O1) did (D1) ) – O1 ) O1 / ( did (D1) ) name ( O1 / ( did (D1) ) ) ⋈ P1 )