SlideShare une entreprise Scribd logo
1  sur  58
Télécharger pour lire hors ligne
relationele algebra

Katrien Verbert
Katrien.Verbert@cs.kuleuven.be

2011-2012
inhoud deze les

•  Relationele algebra
•  (E)ER naar relationeel schema




                                   2
relationele model: herhaling terminologie

•    relatie: een tabel met kolommen en rijen
•    attribuut: een kolom van een relatie
•    tupel: een rij van een relatie.
•    domein: verzameling van toegelaten waarden voor 1 of
     meerdere attributen. Voorbeelden zijn “integers”,
     “strings”, “datum”, …




                                                            3
4
relationele vraagtalen

•  vraagtaal (query language) = gegevensmanipulatietaal
•  biedt functionaliteit voor
   –    opvragen
   –    toevoegen
   –    verwijderen
   –    wijzigen van gegevens




                                                          5
indeling van relationele vraagtalen

•  Algebraïsche talen              •  Calculustalen
   –  steunen op relationele algebra   –  steunen op relationele calculus
   –  gebruiken operatoren             –  gebruiken formele beschrijving
                                          van gewenste info
   –  proceduraal
                                           •  predikatenlogica
                                       –  niet-proceduraal
                                       –  2 soorten:
                                           •  tupel-calculus,
                                           •  domein-calculus




                                                                            6
relationele algebra


•  verzamelingsoperatoren
   –  unie, doorsnede, verschil, cartesisch product


•  relationele operatoren
   –  selectie, projectie, join, deling, hernoeming



•  unaire of binaire operatoren




                                                      7
selectie




           8
selectie
                        σ<selectiecriterium>(R)

•  selecteert een aantal tupels uit een extensie (= rijen uit een tabel)

•  resultaat:
    –  een relatie (tabel) met zelfde tupelschema
    –  deelverzameling van de oorspronkelijke extensie


•  selectiecriterium F = (logische) formule
    –  enkelvoudige formules: =, ≠, <, >, <=, >=
    –  meervoudige formules: logische operatoren ∧, ∨, ¬

    De	
  selec'e	
  van	
  tupels	
  uit	
  extensie	
  r	
  van	
  rela'e	
  R	
  onder	
  formule	
  F	
  
    is	
  de	
  verzameling	
  van	
  alle	
  tupels	
  uit	
  r	
  die	
  voldoen	
  aan	
  F:	
  
    σF(r)	
  =	
  {t	
  |	
  t	
  ∈	
  r	
  ∧	
  t	
  voldoet	
  aan	
  F}	
  
                                                                                                                9
voorbeelden

•  σDNO=4 (EMPLOYEE)
•  σSALARY > 30000 (EMPLOYEE)
•  σ (DNO = 4 ∧ SALARY > 25000) v (DNO = 5 ∧ SALARY > 30000)(EMPLOYEE)




                                                                  10
oefening: geef alle rode of groene boten
         sid bid  day
Reserves 22 101 10/10/96
         58 103 11/12/96
          sid   sname rating age
Sailors   22    dustin  7    45.0
          31    lubber  8    55.5
          58    rusty   10 35.0
Boats     bid    bname      color
          101   Interlake   Blue
          102   Interlake   Red
          103   Clipper     Green
          104   Marine      Red
oplossing


    "                               (Boats)
        color='red'#color='green'
!
eigenschappen van selectie

•  behoudt het schema
•  σ(r) ⊆ r; dus kardinaliteit stijgt niet: #(σ(r)) ≤ #r
•  samenstelling van selecties is commutatief
   –  gevolg:
   –  σ C1 (σ C2 (… (σ Cn ( r ) ) )...) = σ C1 ∧ C2 ∧... ∧ Cn ( r )




                                                                      13
projectie




            14
projectie

                 π <attributenlijst>(R)
  –  doel: een aantal kolommen uit een tabel halen

  –  resultaat:
      •  verzameling tuples
      •  met attributen deelverzameling van attributen van oorspronkelijke tupels
      •  verbonden met deelverzameling X van het tupelschema




         De	
  projec'e	
  van	
  een	
  extensie	
  r	
  van	
  rela'e	
  R	
  op	
  een	
  	
  
         aAributenverzameling	
  X	
  is	
  
         πX(r)	
  =	
  {	
  t	
  |	
  tupelschema	
  van	
  t	
  is	
  X	
  en	
  ∃	
  t’	
  ∈	
  r	
  :	
  t	
  ⊆	
  t’	
  }	
  
                                                                                                                                    15
eigenschappen van projectie

•  # π X ( r ) ≤ # r
    –  reden: dubbels worden verwijderd
    –  # πX(r) = # r indien X een sleutel bevat
•  πX (πY ( r ) ) enkel gedefinieerd indien X ⊆ Y
    –  dus niet commutatief !!
•  Idempotent
    –  enkel allerlaatste (buitenste) projectie moet uitgevoerd worden :
    –  πX1 ( πX2 (… ( r ) )...) = πX1 ( r )




                                                                      16
samenstelling van uitdrukkingen
•  samenstelling in 1 nieuwe uitdrukking
    –  vb. πFNAME, LNAME, SALARY ( σDNO = 5 ( EMPLOYEE ) )

•  opeenvolgende berekeningen met expliciete benoeming van
   tussenresultaten
    –  DEP5_EMPS ← σDNO=5 ( EMPLOYEE )
    –  RESULT ← πFNAME, LNAME, SALARY (DEP5_EMPS)

•  selectie en projectie commuteren indien de attributen in het
   selectiecriterium behoren tot de attributen waarop wordt
   geprojecteerd
    –  πX (σ F ( r ) ) = σF ( πX ( r ) ) indien F enkel attributen in X gebruikt
18
Find names of sailors who are younger
than 50
         sid bid  day
Reserves 22 101 10/10/96            Syntax	
  
         58 103 11/12/96            	
  
                                    selec'e:	
  	
  σ<criterium>(R)	
  
          sid   sname rating age    projec'e:	
  	
  π<aAributen>(R)	
  
Sailors   22    dustin  7    45.0   	
  
                                    	
  
          31    lubber  8    55.5
          58    rusty   10 35.0
Boats     bid    bname      color
          101   Interlake   Blue
          102   Interlake   Red
          103   Clipper     Green
          104   Marine      Red
Find names of sailors who are younger
than 50
         sid bid  day
Reserves 22 101 10/10/96            Oplossing	
  
         58 103 11/12/96            	
  
                                    πsname(σage<50(Sailors))	
  
          sid   sname rating age    	
  
Sailors   22    dustin  7    45.0   	
  

          31    lubber  8    55.5
          58    rusty   10 35.0
Boats     bid    bname      color
          101   Interlake   Blue
          102   Interlake   Red
          103   Clipper     Green
          104   Marine      Red
hernoeming
–  doel: wijziging van attribuutnamen
–  notatie: nieuwe namen tussen haakjes vermeld
–  voorbeeld:

      RESULT(Firstname, Lastname, Salary)
                         ← πFNAME, LNAME, SALARY (DEP5_EMPS)




 –  hernoeming kan ook met een (unaire) operator ρ voorgesteld worden


   1.  ρ S(B1, B2,…, Bn) (R)   relatie en attributen worden hernoemd
   2.  ρ S (R)                 alleen relatie wordt hernoemd
   3.  ρ (B1, B2,…, Bn) (R)    alleen attributen worden hernoemd

                                                                       21
(a) π FNAME, LNAME, SALARY (σ DNO = 5 (EMPLOYEE ) )

(b) zelfde met tussenresultaat en hernoeming van attributen
Unie ∪, doorsnede ∩, verschil 

–  enkel toegelaten op vergelijkbare ("union compatible") relaties
–  definitie
        2 relaties R( A1,...,An) en S (B1,...,Bm) zijn vergelijkbaar
                            als en slechts als

        m=n            (d.w.z. R en S hebben dezelfde graad)
        DOM (Ai) = DOM (Bi)     voor 1 ≤ i ≤ n

–  schema-behoudend, op attribuutnamen na
    •  afspraak: behoud attribuutnamen van 1-ste relatie




                                                                       23
RESULT ← RESULT1 ∪ RESULT2




                             24
25
Cartesisch product

•  Zij gegeven de relaties
   –  R ( A1,...,An )
   –  S ( B1,...,Bm )
   –  die niet noodzakelijk vergelijkbaar zijn


•  Q = R × S
   –  heeft schema Q(A1,...,An,B1,...,Bm)
   –  en bevat elke combinatie van tupels uit R en S




                                                       26
Cartesisch product: voorbeeld
                             sid   sname rating age
sid bid  day
                             22    dustin  7    45.0
22 101 10/10/96              31    lubber  8    55.5
58 103 11/12/96              58    rusty   10 35.0
       R1
                                            S1

            (sid) sname    rating age     (sid) bid    day
             22   dustin     7     45.0    22    101   10/10/96
R1 X S1 =    22   dustin     7     45.0    58    103   11/12/96
             31   lubber     8     55.5    22    101   10/10/96
             31   lubber     8     55.5    58    103   11/12/96
             58   rusty      10    35.0    22    101   10/10/96
             58   rusty      10    35.0    58    103   11/12/96
FEMALE_EMP
  ← σSEX = F (EMPLOYEE)

EMPNAMES
  ← π FNAME, LNAME, SSN (FEMALE_EMP)

EMP_DEPENDENTS
  ← EMPNAMES × DEPENDENT

ACTUAL_DEPENDENTS
  ← σ SSN = ESSN (EMP_DEPENDENTS)

RESULT
  ← π FNAME, LNAME, DEPENDENT_NAME
       (ACTUAL_DEPENDENTS )




                                       28
join operator

•  binaire operator
   –  combineert gerelateerde tupels van 2 relaties
•  = cartesisch product + selectie

•  notatie
                       R wvF S
   –  met F een selectiecriterium


•  voorbeeld
   –  ACTUAL_DEPENDENTS ← EMPNAMES wvSSN=ESSN DEPENDENT

                                                        29
join operator
–  voorbeeld: combineer voor alle departementen informatie over
   het departement + de manager ervan:

                  DEPARTMENT wv MGRSSN = SSN EMPLOYEE




 De	
  join	
  van	
  R	
  en	
  S	
  volgens	
  criterium	
  F	
  is	
  	
  
 R	
  wv	
  F	
  S	
  =	
  σF	
  (	
  R	
  ×	
  S	
  )	
  

                                                                                30
soorten joins
•  Opdeling naargelang van de vorm van de join-voorwaarde F
   –  F = C1 ∧ C2 ∧ … ∧ Cn


•  theta-join: elke Ck is van de vorm Ai θ Bj met
   –  θ ∈ { =, <, >, ≤, ≥, ≠ }
   –  DOM (Ai) = DOM (Bj)


•  speciale gevallen
   –  equi-join: enkel " = "
   –  natuurlijke join
       •  equi-join + weglaten van overtollige attributen
                  (d.w.z. per voorwaarde Ai = Bj enkel Ai of Bj behouden)
       •  notatie: R ÚF S

                                                                            31
vereenvoudigde notaties voor natuurlijke joins

•  R Ú X,Y S
   –  met X en Y lijsten van attributen
   –  alle attribuutwaarden moeten aan elkaar gelijk zijn
•  R Ú S
   –  lijsten X en Y zijn impliciet: bevatten alle attributen
      die dezelfde naam hebben in R en S




                                                                32
natural join voorbeeld
                         sid    sname rating age
sid bid  day             22     dustin  7    45.0
22 101 10/10/96          31     lubber  8    55.5
58 103 11/12/96          58     rusty   10 35.0
        R1
                                        S1

R1 * S1 =
  sid    sname    rating age     bid   day
  22     dustin   7      45.0    101   10/10/96
  58     rusty    10     35.0    103   11/12/96
(a) PROJ_DEPT ← PROJECT Ú DEPARTMENT

(b) DEPT_LOCS ← DEPARTMENT Ú DEPT_LOCATIONS
Find names of sailors who have reserved boat
#103
         sid bid  day
Reserves 22 101 10/10/96            Syntax	
  
         58 103 11/12/96            	
  
                                    selectie: σ<criterium>(R)
          sid   sname rating age    projectie: π<attributen>(R)
                                    join: R wvF S
Sailors   22    dustin  7    45.0   natural join: R*S
          31    lubber  8    55.5   	
  
                                    	
  
          58    rusty   10 35.0
Boats     bid    bname      color
          101   Interlake   Blue
          102   Interlake   Red
          103   Clipper     Green
          104   Marine      Red
Find names of sailors who have
reserved boat #103
•  Oplossing 1:
                     " sname((#             Reserves)*Sailors)
                                  bid=103
•  Oplossing 2: !

                    " sname(#          (Reserves*Sailors))
                                bid=103
              !
fundamentele operatoren




                          37
fundamentele operatoren

•  de verzameling operatoren {σ, π, ∪, , ×} is volledig:
   –  andere operatoren kunnen op basis van deze gedefinieerd worden.
   –  vandaar de naam: fundamentele operatoren.


•  niet-fundamentele operatoren:
   –    join                 combinatie van σ, π, ×
   –    ∩                    R∩S=R∪S(RS)(SR)
   –    ...
   –    zijn niet strikt nodig
   –    wel gemakkelijk


•  nog een niet-fundamentele operator:
   –  de deling       ÷
                                                                38
deling
•  Q = R ÷ S

   –  ≈ inverse van cartesisch product
       •  ⇔ Q is de maximale relatie waarvoor geldt dat Q × S ⊆ R
       •  Q bevat enkel de attributen van R die niet in S zitten


   –  voorbeeld: "geef alle werknemers die werken aan elk project
      waaraan John Smith werkt”

       SMITH ← σ FNAME = ‘John’ AND LNAME = ‘Smith’ ( EMPLOYEE )
           geeft EMPLOYEE-tupel ‘John Smith’
       SMITH_PNOS ← π PNO ( WORKS_ON wv ESSN = SSN SMITH )
           geeft alle projecten waaraan John Smith werkt
       SSN_PNOS ← π ESSN, PNO ( WORKS_ON )
           geeft voor alle werknemers alle projecten waaraan ze werken
       SSNS(SSN) ← SSN_PNOS ÷ SMITH_PNOS
                                                                         39
           deling geeft SSN's van gevraagde werknemers
41
oefening: find the names of sailors who
have reserved all boats
         sid bid  day
Reserves 22 101 10/10/96            Syntax	
  
         58 103 11/12/96            	
  
                                    selectie: σ<criterium>(R)
          sid   sname rating age    projectie: π<attributen>(R)
                                    join: R wvF S
Sailors   22    dustin  7    45.0   natural join: R*S
                                    deling=R÷S
          31    lubber  8    55.5   	
  
          58    rusty   10 35.0     	
  
Boats     bid    bname      color
          101   Interlake   Blue
          102   Interlake   Red
          103   Clipper     Green
          104   Marine      Red
Find the names of sailors who have
     reserved all boats

    Tempsids $
            "#
            #              (Reserves) / $         (Boats)
                 sid,bid                    bid
!



       ! sname (Tempsids*Sailors)
aggregaatfuncties
•  functies die op verzamelingen waarden uitgevoerd worden
   –  SUM, AVERAGE, MAX, MIN, COUNT


•  notatie

                           groepering     ℑ functies (R)
       •  groepering = verz. attributen op basis waarvan groepering gebeurt
       •  functies = lijst van koppels ( functie, attribuut )



•  voorbeeld:
                 Dno ℑ AVERAGE Salary           ( EMPLOYEE )

                                                                              44
aggregaatfuncties
•  resultaat: tabel met als attributen
   –  attributen uit de groepering
   –  attributen met naam “Functie_attribuut” die het resultaat van de
      functie op dat attribuut geven


•  voorbeeld:
   –  Dno ℑ COUNT Ssn, AVERAGE Salary ( EMPLOYEE )

   –  geeft tabel met attributen: Dno, Count_ssn, Average_salary


•  groeperingsattributen kunnen weggelaten worden
   –  → aggregaatfunctie toegepast op de hele relatie
        resultaat: 1 tupel
                                                                     45
(a)	
  	
  R	
  (	
  Dno,	
  No_of_employees,	
  Average_sal	
  )	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  ←	
  Dno	
  ℑ COUNT	
  Ssn,	
  AVERAGE	
  Salary	
  (EMPLOYEE	
  )	
  
	
  
(b)	
  	
  Dno	
  ℑ COUNT	
  Ssn,	
  AVERAGE	
  Salary	
  (EMPLOYEE	
  )	
  
	
  
(c)	
  ℑ COUNT	
  Ssn,	
  AVERAGE	
  Salary	
  (EMPLOYEE	
  )	
  
recursieve sluiting

•  vb. 1
   –  vind alle ondergeschikten van persoon Y
   –  = transitieve sluiting van ” X heeft Y als chef "
•  vb. 2
   –  in een stamboom-databank van honden:
   –  vind alle voorouders van “zwerver”
•  niet algemeen uit te drukken in relationele algebra
   –  wel voor bepaald aantal niveaus, bv. vind alle ouders, vind alle
      grootouders, ...
   –  relationele uitdrukking groeit per niveau dat erbij komt
   –  onbeperkt aantal niveaus zou oneindige uitdrukking geven



                                                                     47
48
uitwendige join

•  gewone joins, bv. R * S,
   –  leveren over de tupels die niet aan de join voorwaarde voldoen
      geen enkele informatie op
   –  vb.
       •  lijst van alle werknemers + als ze een departement leiden: naam van dat
          departement
       •  join geeft enkel werknemers die effectief een departement leiden

•  linkse uitwendige join
   –  levert info over alle werknemers
   –  + info over het departement dat ze leiden, of nul als ze geen
      departement leiden
•  analoog:
   –  rechtse uitwendige join
   –  volledige uitwendige join
                                                                                    49
TEMP	
  ←	
  (	
  EMPLOYEE	
   	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  Ssn	
  =	
  Mgr_ssn	
  DEPARTMENT	
  )	
  
	
  
RESULT	
  ← π Fname,	
  Minit,	
  Lname,	
  Dname	
  	
  (	
  TEMP	
  )	
  
                                                                                                                        50
varianten op unie

•  Vereniging van tupels van niet vergelijkbare relaties
                           +

•  Uitwendige unie: ∪+
                   +
   –  Notatie : Q = R ∪ S +	

   –  Attr (Q) = Attr (R) ∪ Attr (S)
   –  nulwaarde voor attributen die niet van toepassing zijn
                                     -

                            ∪-
                              -	

•  Inwendige unie:
   –  Notatie : Q = R ∪ - S
   –  Attr(Q) = Attr(R) ∪ - Attr(S)
       •  ( alleen gemeenschappelijke attributen blijven behouden )



                                                                      51
voorbeelden van queries

     –  Q 1:
         •  Retrieve the name and address of all employees who work for the
            ‘Research’ department


RESEARCH_DEPT ← σ DNAME =           Research   ( DEPARTMENT )

RESEARCH_EMPS ← ( RESEARCH_DEPT wv Dnumber = Dno EMPLOYEE )

RESULT ← π Fname, Lname, Address ( RESEARCH_EMPS )




                                                                              52
voorbeelden van queries

  –  Q 3:
      •  Find the names of employees who work on all the projects controlled by
         department number 5

   DEPT5_PROJS ( Pno ) ← π Pnumber (σ Dnum = 5 ( PROJECT ) )

   EMP_PROJ ( Ssn, Pno ) ← π Essn, Pno ( WORKS_ON )

   RESULT_EMP_SSNS ← EMP_PROJ ÷ DEPT5_PROJS

   RESULT ← π Lname, Fname ( RESULT_EMP_SSNS Ú EMPLOYEE )




                                                                                  53
voorbeelden van queries
 –  Q 4:
     •  Make a list of projects that involve an employee whose last name is ‘Smith’,
        either as a worker or as a manager of the department that controls the project


 SMITHS (Essn) ← π SSN (σ Lname =      Smith   ( EMPLOYEE ) )

 SMITH_WORKER_PROJ ← π Pno ( WORKS_ON Ú SMITHS )


 MGRS ← π Lname, Dnumber (EMPLOYEE wv Ssn = Mgr_ssn DEPARTMENT)

 SMITH_MANAGED_DEPTS (Dnum) ← π Dnumber (σ Lname =                  Smith   (MGRS) )

 SMITH_MGR_PROJS (Pno) ←
               π Pnumber ( SMITH_MANAGED_DEPTS Ú PROJECT )

 RESULT ← (SMITH_WORKER_PROJ ∪ SMITH_MGR_PROJS )

                                                                                    54
voorbeelden van queries

•  Q 5:
    –  List the names of all employees with two or more dependents


T1 (Ssn, No_of_dependents) ← EssnFCOUNT Dependent_name (DEPENDENT)


T2 ← σ No_of_dependents ≥ 2 ( T1 )


RESULT ← π Lname, Fname ( T2 Ú EMPLOYEE )




                                                                     55
voorbeelden van queries

•  Q 6:
   –  Retrieve the names of employees who have no dependents


  ALL_EMPS ← π Ssn ( EMPLOYEE )


 EMPS_WITH_DEPS ( Ssn ) ← π Essn ( DEPENDENT )


 EMPS_WITHOUT_DEPS ← ALL_EMPS  EMPS_WITH_DEPS


 RESULT ← π Lname, Fname ( EMPS_WITHOUT_DEPS Ú EMPLOYEE )


                                                               56
voorbeelden van queries
–  Q 7:
    •  List the names of managers who have at least one
       dependent


 MGS ( Ssn ) ← π Mgr_ssn ( DEPARTMENT )


 EMPS_WITH_DEPS ( Ssn ) ← π Essn ( DEPENDENT )



 MGRS_WITH_DEPS ← MGRS ∩ EMPS_WITH_DEPS

RESULT ← π Lname, Fname ( MGRS_WITH_DEPS Ú EMPLOYEE )



                                                          57
VRAGEN?




          58

Contenu connexe

Similaire à Relationele algebra

Handleiding r aw van der vaart
Handleiding r   aw van der vaartHandleiding r   aw van der vaart
Handleiding r aw van der vaartdarkhomey
 
20130214 les gb2
20130214 les gb220130214 les gb2
20130214 les gb2Erik Duval
 
Integraalrekening 1 les 5
Integraalrekening 1 les 5Integraalrekening 1 les 5
Integraalrekening 1 les 5Bart Habraken
 
wiskundeA
wiskundeAwiskundeA
wiskundeAVSOED
 

Similaire à Relationele algebra (7)

Normalisatie - deel 2
Normalisatie - deel 2Normalisatie - deel 2
Normalisatie - deel 2
 
Handleiding r aw van der vaart
Handleiding r   aw van der vaartHandleiding r   aw van der vaart
Handleiding r aw van der vaart
 
20130214 les gb2
20130214 les gb220130214 les gb2
20130214 les gb2
 
Fis 02relations
Fis 02relationsFis 02relations
Fis 02relations
 
Integraalrekening 1 les 5
Integraalrekening 1 les 5Integraalrekening 1 les 5
Integraalrekening 1 les 5
 
SQL - deel 1
SQL - deel 1SQL - deel 1
SQL - deel 1
 
wiskundeA
wiskundeAwiskundeA
wiskundeA
 

Plus de Katrien Verbert

Human-centered AI: how can we support end-users to interact with AI?
Human-centered AI: how can we support end-users to interact with AI?Human-centered AI: how can we support end-users to interact with AI?
Human-centered AI: how can we support end-users to interact with AI?Katrien Verbert
 
Human-centered AI: how can we support end-users to interact with AI?
Human-centered AI: how can we support end-users to interact with AI?Human-centered AI: how can we support end-users to interact with AI?
Human-centered AI: how can we support end-users to interact with AI?Katrien Verbert
 
Human-centered AI: how can we support lay users to understand AI?
Human-centered AI: how can we support lay users to understand AI?Human-centered AI: how can we support lay users to understand AI?
Human-centered AI: how can we support lay users to understand AI?Katrien Verbert
 
Explaining job recommendations: a human-centred perspective
Explaining job recommendations: a human-centred perspectiveExplaining job recommendations: a human-centred perspective
Explaining job recommendations: a human-centred perspectiveKatrien Verbert
 
Explaining recommendations: design implications and lessons learned
Explaining recommendations: design implications and lessons learnedExplaining recommendations: design implications and lessons learned
Explaining recommendations: design implications and lessons learnedKatrien Verbert
 
Designing Learning Analytics Dashboards: Lessons Learned
Designing Learning Analytics Dashboards: Lessons LearnedDesigning Learning Analytics Dashboards: Lessons Learned
Designing Learning Analytics Dashboards: Lessons LearnedKatrien Verbert
 
Human-centered AI: towards the next generation of interactive and adaptive ex...
Human-centered AI: towards the next generation of interactive and adaptive ex...Human-centered AI: towards the next generation of interactive and adaptive ex...
Human-centered AI: towards the next generation of interactive and adaptive ex...Katrien Verbert
 
Explainable AI for non-expert users
Explainable AI for non-expert usersExplainable AI for non-expert users
Explainable AI for non-expert usersKatrien Verbert
 
Towards the next generation of interactive and adaptive explanation methods
Towards the next generation of interactive and adaptive explanation methodsTowards the next generation of interactive and adaptive explanation methods
Towards the next generation of interactive and adaptive explanation methodsKatrien Verbert
 
Personalized food recommendations: combining recommendation, visualization an...
Personalized food recommendations: combining recommendation, visualization an...Personalized food recommendations: combining recommendation, visualization an...
Personalized food recommendations: combining recommendation, visualization an...Katrien Verbert
 
Explaining and Exploring Job Recommendations: a User-driven Approach for Inte...
Explaining and Exploring Job Recommendations: a User-driven Approach for Inte...Explaining and Exploring Job Recommendations: a User-driven Approach for Inte...
Explaining and Exploring Job Recommendations: a User-driven Approach for Inte...Katrien Verbert
 
Learning analytics for feedback at scale
Learning analytics for feedback at scaleLearning analytics for feedback at scale
Learning analytics for feedback at scaleKatrien Verbert
 
Interactive recommender systems and dashboards for learning
Interactive recommender systems and dashboards for learningInteractive recommender systems and dashboards for learning
Interactive recommender systems and dashboards for learningKatrien Verbert
 
Interactive recommender systems: opening up the “black box”
Interactive recommender systems: opening up the “black box”Interactive recommender systems: opening up the “black box”
Interactive recommender systems: opening up the “black box”Katrien Verbert
 
Interactive Recommender Systems
Interactive Recommender SystemsInteractive Recommender Systems
Interactive Recommender SystemsKatrien Verbert
 
Web Information Systems Lecture 2: HTML
Web Information Systems Lecture 2: HTMLWeb Information Systems Lecture 2: HTML
Web Information Systems Lecture 2: HTMLKatrien Verbert
 
Information Visualisation: perception and principles
Information Visualisation: perception and principlesInformation Visualisation: perception and principles
Information Visualisation: perception and principlesKatrien Verbert
 
Web Information Systems Lecture 1: Introduction
Web Information Systems Lecture 1: IntroductionWeb Information Systems Lecture 1: Introduction
Web Information Systems Lecture 1: IntroductionKatrien Verbert
 
Information Visualisation: Introduction
Information Visualisation: IntroductionInformation Visualisation: Introduction
Information Visualisation: IntroductionKatrien Verbert
 

Plus de Katrien Verbert (20)

Explainability methods
Explainability methodsExplainability methods
Explainability methods
 
Human-centered AI: how can we support end-users to interact with AI?
Human-centered AI: how can we support end-users to interact with AI?Human-centered AI: how can we support end-users to interact with AI?
Human-centered AI: how can we support end-users to interact with AI?
 
Human-centered AI: how can we support end-users to interact with AI?
Human-centered AI: how can we support end-users to interact with AI?Human-centered AI: how can we support end-users to interact with AI?
Human-centered AI: how can we support end-users to interact with AI?
 
Human-centered AI: how can we support lay users to understand AI?
Human-centered AI: how can we support lay users to understand AI?Human-centered AI: how can we support lay users to understand AI?
Human-centered AI: how can we support lay users to understand AI?
 
Explaining job recommendations: a human-centred perspective
Explaining job recommendations: a human-centred perspectiveExplaining job recommendations: a human-centred perspective
Explaining job recommendations: a human-centred perspective
 
Explaining recommendations: design implications and lessons learned
Explaining recommendations: design implications and lessons learnedExplaining recommendations: design implications and lessons learned
Explaining recommendations: design implications and lessons learned
 
Designing Learning Analytics Dashboards: Lessons Learned
Designing Learning Analytics Dashboards: Lessons LearnedDesigning Learning Analytics Dashboards: Lessons Learned
Designing Learning Analytics Dashboards: Lessons Learned
 
Human-centered AI: towards the next generation of interactive and adaptive ex...
Human-centered AI: towards the next generation of interactive and adaptive ex...Human-centered AI: towards the next generation of interactive and adaptive ex...
Human-centered AI: towards the next generation of interactive and adaptive ex...
 
Explainable AI for non-expert users
Explainable AI for non-expert usersExplainable AI for non-expert users
Explainable AI for non-expert users
 
Towards the next generation of interactive and adaptive explanation methods
Towards the next generation of interactive and adaptive explanation methodsTowards the next generation of interactive and adaptive explanation methods
Towards the next generation of interactive and adaptive explanation methods
 
Personalized food recommendations: combining recommendation, visualization an...
Personalized food recommendations: combining recommendation, visualization an...Personalized food recommendations: combining recommendation, visualization an...
Personalized food recommendations: combining recommendation, visualization an...
 
Explaining and Exploring Job Recommendations: a User-driven Approach for Inte...
Explaining and Exploring Job Recommendations: a User-driven Approach for Inte...Explaining and Exploring Job Recommendations: a User-driven Approach for Inte...
Explaining and Exploring Job Recommendations: a User-driven Approach for Inte...
 
Learning analytics for feedback at scale
Learning analytics for feedback at scaleLearning analytics for feedback at scale
Learning analytics for feedback at scale
 
Interactive recommender systems and dashboards for learning
Interactive recommender systems and dashboards for learningInteractive recommender systems and dashboards for learning
Interactive recommender systems and dashboards for learning
 
Interactive recommender systems: opening up the “black box”
Interactive recommender systems: opening up the “black box”Interactive recommender systems: opening up the “black box”
Interactive recommender systems: opening up the “black box”
 
Interactive Recommender Systems
Interactive Recommender SystemsInteractive Recommender Systems
Interactive Recommender Systems
 
Web Information Systems Lecture 2: HTML
Web Information Systems Lecture 2: HTMLWeb Information Systems Lecture 2: HTML
Web Information Systems Lecture 2: HTML
 
Information Visualisation: perception and principles
Information Visualisation: perception and principlesInformation Visualisation: perception and principles
Information Visualisation: perception and principles
 
Web Information Systems Lecture 1: Introduction
Web Information Systems Lecture 1: IntroductionWeb Information Systems Lecture 1: Introduction
Web Information Systems Lecture 1: Introduction
 
Information Visualisation: Introduction
Information Visualisation: IntroductionInformation Visualisation: Introduction
Information Visualisation: Introduction
 

Relationele algebra

  • 2. inhoud deze les •  Relationele algebra •  (E)ER naar relationeel schema 2
  • 3. relationele model: herhaling terminologie •  relatie: een tabel met kolommen en rijen •  attribuut: een kolom van een relatie •  tupel: een rij van een relatie. •  domein: verzameling van toegelaten waarden voor 1 of meerdere attributen. Voorbeelden zijn “integers”, “strings”, “datum”, … 3
  • 4. 4
  • 5. relationele vraagtalen •  vraagtaal (query language) = gegevensmanipulatietaal •  biedt functionaliteit voor –  opvragen –  toevoegen –  verwijderen –  wijzigen van gegevens 5
  • 6. indeling van relationele vraagtalen •  Algebraïsche talen •  Calculustalen –  steunen op relationele algebra –  steunen op relationele calculus –  gebruiken operatoren –  gebruiken formele beschrijving van gewenste info –  proceduraal •  predikatenlogica –  niet-proceduraal –  2 soorten: •  tupel-calculus, •  domein-calculus 6
  • 7. relationele algebra •  verzamelingsoperatoren –  unie, doorsnede, verschil, cartesisch product •  relationele operatoren –  selectie, projectie, join, deling, hernoeming •  unaire of binaire operatoren 7
  • 9. selectie σ<selectiecriterium>(R) •  selecteert een aantal tupels uit een extensie (= rijen uit een tabel) •  resultaat: –  een relatie (tabel) met zelfde tupelschema –  deelverzameling van de oorspronkelijke extensie •  selectiecriterium F = (logische) formule –  enkelvoudige formules: =, ≠, <, >, <=, >= –  meervoudige formules: logische operatoren ∧, ∨, ¬ De  selec'e  van  tupels  uit  extensie  r  van  rela'e  R  onder  formule  F   is  de  verzameling  van  alle  tupels  uit  r  die  voldoen  aan  F:   σF(r)  =  {t  |  t  ∈  r  ∧  t  voldoet  aan  F}   9
  • 10. voorbeelden •  σDNO=4 (EMPLOYEE) •  σSALARY > 30000 (EMPLOYEE) •  σ (DNO = 4 ∧ SALARY > 25000) v (DNO = 5 ∧ SALARY > 30000)(EMPLOYEE) 10
  • 11. oefening: geef alle rode of groene boten sid bid day Reserves 22 101 10/10/96 58 103 11/12/96 sid sname rating age Sailors 22 dustin 7 45.0 31 lubber 8 55.5 58 rusty 10 35.0 Boats bid bname color 101 Interlake Blue 102 Interlake Red 103 Clipper Green 104 Marine Red
  • 12. oplossing " (Boats) color='red'#color='green' !
  • 13. eigenschappen van selectie •  behoudt het schema •  σ(r) ⊆ r; dus kardinaliteit stijgt niet: #(σ(r)) ≤ #r •  samenstelling van selecties is commutatief –  gevolg: –  σ C1 (σ C2 (… (σ Cn ( r ) ) )...) = σ C1 ∧ C2 ∧... ∧ Cn ( r ) 13
  • 14. projectie 14
  • 15. projectie π <attributenlijst>(R) –  doel: een aantal kolommen uit een tabel halen –  resultaat: •  verzameling tuples •  met attributen deelverzameling van attributen van oorspronkelijke tupels •  verbonden met deelverzameling X van het tupelschema De  projec'e  van  een  extensie  r  van  rela'e  R  op  een     aAributenverzameling  X  is   πX(r)  =  {  t  |  tupelschema  van  t  is  X  en  ∃  t’  ∈  r  :  t  ⊆  t’  }   15
  • 16. eigenschappen van projectie •  # π X ( r ) ≤ # r –  reden: dubbels worden verwijderd –  # πX(r) = # r indien X een sleutel bevat •  πX (πY ( r ) ) enkel gedefinieerd indien X ⊆ Y –  dus niet commutatief !! •  Idempotent –  enkel allerlaatste (buitenste) projectie moet uitgevoerd worden : –  πX1 ( πX2 (… ( r ) )...) = πX1 ( r ) 16
  • 17. samenstelling van uitdrukkingen •  samenstelling in 1 nieuwe uitdrukking –  vb. πFNAME, LNAME, SALARY ( σDNO = 5 ( EMPLOYEE ) ) •  opeenvolgende berekeningen met expliciete benoeming van tussenresultaten –  DEP5_EMPS ← σDNO=5 ( EMPLOYEE ) –  RESULT ← πFNAME, LNAME, SALARY (DEP5_EMPS) •  selectie en projectie commuteren indien de attributen in het selectiecriterium behoren tot de attributen waarop wordt geprojecteerd –  πX (σ F ( r ) ) = σF ( πX ( r ) ) indien F enkel attributen in X gebruikt
  • 18. 18
  • 19. Find names of sailors who are younger than 50 sid bid day Reserves 22 101 10/10/96 Syntax   58 103 11/12/96   selec'e:    σ<criterium>(R)   sid sname rating age projec'e:    π<aAributen>(R)   Sailors 22 dustin 7 45.0     31 lubber 8 55.5 58 rusty 10 35.0 Boats bid bname color 101 Interlake Blue 102 Interlake Red 103 Clipper Green 104 Marine Red
  • 20. Find names of sailors who are younger than 50 sid bid day Reserves 22 101 10/10/96 Oplossing   58 103 11/12/96   πsname(σage<50(Sailors))   sid sname rating age   Sailors 22 dustin 7 45.0   31 lubber 8 55.5 58 rusty 10 35.0 Boats bid bname color 101 Interlake Blue 102 Interlake Red 103 Clipper Green 104 Marine Red
  • 21. hernoeming –  doel: wijziging van attribuutnamen –  notatie: nieuwe namen tussen haakjes vermeld –  voorbeeld: RESULT(Firstname, Lastname, Salary) ← πFNAME, LNAME, SALARY (DEP5_EMPS) –  hernoeming kan ook met een (unaire) operator ρ voorgesteld worden 1.  ρ S(B1, B2,…, Bn) (R) relatie en attributen worden hernoemd 2.  ρ S (R) alleen relatie wordt hernoemd 3.  ρ (B1, B2,…, Bn) (R) alleen attributen worden hernoemd 21
  • 22. (a) π FNAME, LNAME, SALARY (σ DNO = 5 (EMPLOYEE ) ) (b) zelfde met tussenresultaat en hernoeming van attributen
  • 23. Unie ∪, doorsnede ∩, verschil –  enkel toegelaten op vergelijkbare ("union compatible") relaties –  definitie 2 relaties R( A1,...,An) en S (B1,...,Bm) zijn vergelijkbaar als en slechts als m=n (d.w.z. R en S hebben dezelfde graad) DOM (Ai) = DOM (Bi) voor 1 ≤ i ≤ n –  schema-behoudend, op attribuutnamen na •  afspraak: behoud attribuutnamen van 1-ste relatie 23
  • 24. RESULT ← RESULT1 ∪ RESULT2 24
  • 25. 25
  • 26. Cartesisch product •  Zij gegeven de relaties –  R ( A1,...,An ) –  S ( B1,...,Bm ) –  die niet noodzakelijk vergelijkbaar zijn •  Q = R × S –  heeft schema Q(A1,...,An,B1,...,Bm) –  en bevat elke combinatie van tupels uit R en S 26
  • 27. Cartesisch product: voorbeeld sid sname rating age sid bid day 22 dustin 7 45.0 22 101 10/10/96 31 lubber 8 55.5 58 103 11/12/96 58 rusty 10 35.0 R1 S1 (sid) sname rating age (sid) bid day 22 dustin 7 45.0 22 101 10/10/96 R1 X S1 = 22 dustin 7 45.0 58 103 11/12/96 31 lubber 8 55.5 22 101 10/10/96 31 lubber 8 55.5 58 103 11/12/96 58 rusty 10 35.0 22 101 10/10/96 58 rusty 10 35.0 58 103 11/12/96
  • 28. FEMALE_EMP ← σSEX = F (EMPLOYEE) EMPNAMES ← π FNAME, LNAME, SSN (FEMALE_EMP) EMP_DEPENDENTS ← EMPNAMES × DEPENDENT ACTUAL_DEPENDENTS ← σ SSN = ESSN (EMP_DEPENDENTS) RESULT ← π FNAME, LNAME, DEPENDENT_NAME (ACTUAL_DEPENDENTS ) 28
  • 29. join operator •  binaire operator –  combineert gerelateerde tupels van 2 relaties •  = cartesisch product + selectie •  notatie R wvF S –  met F een selectiecriterium •  voorbeeld –  ACTUAL_DEPENDENTS ← EMPNAMES wvSSN=ESSN DEPENDENT 29
  • 30. join operator –  voorbeeld: combineer voor alle departementen informatie over het departement + de manager ervan: DEPARTMENT wv MGRSSN = SSN EMPLOYEE De  join  van  R  en  S  volgens  criterium  F  is     R  wv  F  S  =  σF  (  R  ×  S  )   30
  • 31. soorten joins •  Opdeling naargelang van de vorm van de join-voorwaarde F –  F = C1 ∧ C2 ∧ … ∧ Cn •  theta-join: elke Ck is van de vorm Ai θ Bj met –  θ ∈ { =, <, >, ≤, ≥, ≠ } –  DOM (Ai) = DOM (Bj) •  speciale gevallen –  equi-join: enkel " = " –  natuurlijke join •  equi-join + weglaten van overtollige attributen (d.w.z. per voorwaarde Ai = Bj enkel Ai of Bj behouden) •  notatie: R ÚF S 31
  • 32. vereenvoudigde notaties voor natuurlijke joins •  R Ú X,Y S –  met X en Y lijsten van attributen –  alle attribuutwaarden moeten aan elkaar gelijk zijn •  R Ú S –  lijsten X en Y zijn impliciet: bevatten alle attributen die dezelfde naam hebben in R en S 32
  • 33. natural join voorbeeld sid sname rating age sid bid day 22 dustin 7 45.0 22 101 10/10/96 31 lubber 8 55.5 58 103 11/12/96 58 rusty 10 35.0 R1 S1 R1 * S1 = sid sname rating age bid day 22 dustin 7 45.0 101 10/10/96 58 rusty 10 35.0 103 11/12/96
  • 34. (a) PROJ_DEPT ← PROJECT Ú DEPARTMENT (b) DEPT_LOCS ← DEPARTMENT Ú DEPT_LOCATIONS
  • 35. Find names of sailors who have reserved boat #103 sid bid day Reserves 22 101 10/10/96 Syntax   58 103 11/12/96   selectie: σ<criterium>(R) sid sname rating age projectie: π<attributen>(R) join: R wvF S Sailors 22 dustin 7 45.0 natural join: R*S 31 lubber 8 55.5     58 rusty 10 35.0 Boats bid bname color 101 Interlake Blue 102 Interlake Red 103 Clipper Green 104 Marine Red
  • 36. Find names of sailors who have reserved boat #103 •  Oplossing 1: " sname((# Reserves)*Sailors) bid=103 •  Oplossing 2: ! " sname(# (Reserves*Sailors)) bid=103 !
  • 38. fundamentele operatoren •  de verzameling operatoren {σ, π, ∪, , ×} is volledig: –  andere operatoren kunnen op basis van deze gedefinieerd worden. –  vandaar de naam: fundamentele operatoren. •  niet-fundamentele operatoren: –  join combinatie van σ, π, × –  ∩ R∩S=R∪S(RS)(SR) –  ... –  zijn niet strikt nodig –  wel gemakkelijk •  nog een niet-fundamentele operator: –  de deling ÷ 38
  • 39. deling •  Q = R ÷ S –  ≈ inverse van cartesisch product •  ⇔ Q is de maximale relatie waarvoor geldt dat Q × S ⊆ R •  Q bevat enkel de attributen van R die niet in S zitten –  voorbeeld: "geef alle werknemers die werken aan elk project waaraan John Smith werkt” SMITH ← σ FNAME = ‘John’ AND LNAME = ‘Smith’ ( EMPLOYEE ) geeft EMPLOYEE-tupel ‘John Smith’ SMITH_PNOS ← π PNO ( WORKS_ON wv ESSN = SSN SMITH ) geeft alle projecten waaraan John Smith werkt SSN_PNOS ← π ESSN, PNO ( WORKS_ON ) geeft voor alle werknemers alle projecten waaraan ze werken SSNS(SSN) ← SSN_PNOS ÷ SMITH_PNOS 39 deling geeft SSN's van gevraagde werknemers
  • 40.
  • 41. 41
  • 42. oefening: find the names of sailors who have reserved all boats sid bid day Reserves 22 101 10/10/96 Syntax   58 103 11/12/96   selectie: σ<criterium>(R) sid sname rating age projectie: π<attributen>(R) join: R wvF S Sailors 22 dustin 7 45.0 natural join: R*S deling=R÷S 31 lubber 8 55.5   58 rusty 10 35.0   Boats bid bname color 101 Interlake Blue 102 Interlake Red 103 Clipper Green 104 Marine Red
  • 43. Find the names of sailors who have reserved all boats Tempsids $ "# # (Reserves) / $ (Boats) sid,bid bid ! ! sname (Tempsids*Sailors)
  • 44. aggregaatfuncties •  functies die op verzamelingen waarden uitgevoerd worden –  SUM, AVERAGE, MAX, MIN, COUNT •  notatie groepering ℑ functies (R) •  groepering = verz. attributen op basis waarvan groepering gebeurt •  functies = lijst van koppels ( functie, attribuut ) •  voorbeeld: Dno ℑ AVERAGE Salary ( EMPLOYEE ) 44
  • 45. aggregaatfuncties •  resultaat: tabel met als attributen –  attributen uit de groepering –  attributen met naam “Functie_attribuut” die het resultaat van de functie op dat attribuut geven •  voorbeeld: –  Dno ℑ COUNT Ssn, AVERAGE Salary ( EMPLOYEE ) –  geeft tabel met attributen: Dno, Count_ssn, Average_salary •  groeperingsattributen kunnen weggelaten worden –  → aggregaatfunctie toegepast op de hele relatie resultaat: 1 tupel 45
  • 46. (a)    R  (  Dno,  No_of_employees,  Average_sal  )                                                                                          ←  Dno  ℑ COUNT  Ssn,  AVERAGE  Salary  (EMPLOYEE  )     (b)    Dno  ℑ COUNT  Ssn,  AVERAGE  Salary  (EMPLOYEE  )     (c)  ℑ COUNT  Ssn,  AVERAGE  Salary  (EMPLOYEE  )  
  • 47. recursieve sluiting •  vb. 1 –  vind alle ondergeschikten van persoon Y –  = transitieve sluiting van ” X heeft Y als chef " •  vb. 2 –  in een stamboom-databank van honden: –  vind alle voorouders van “zwerver” •  niet algemeen uit te drukken in relationele algebra –  wel voor bepaald aantal niveaus, bv. vind alle ouders, vind alle grootouders, ... –  relationele uitdrukking groeit per niveau dat erbij komt –  onbeperkt aantal niveaus zou oneindige uitdrukking geven 47
  • 48. 48
  • 49. uitwendige join •  gewone joins, bv. R * S, –  leveren over de tupels die niet aan de join voorwaarde voldoen geen enkele informatie op –  vb. •  lijst van alle werknemers + als ze een departement leiden: naam van dat departement •  join geeft enkel werknemers die effectief een departement leiden •  linkse uitwendige join –  levert info over alle werknemers –  + info over het departement dat ze leiden, of nul als ze geen departement leiden •  analoog: –  rechtse uitwendige join –  volledige uitwendige join 49
  • 50. TEMP  ←  (  EMPLOYEE                        Ssn  =  Mgr_ssn  DEPARTMENT  )     RESULT  ← π Fname,  Minit,  Lname,  Dname    (  TEMP  )   50
  • 51. varianten op unie •  Vereniging van tupels van niet vergelijkbare relaties + •  Uitwendige unie: ∪+ + –  Notatie : Q = R ∪ S + –  Attr (Q) = Attr (R) ∪ Attr (S) –  nulwaarde voor attributen die niet van toepassing zijn - ∪- - •  Inwendige unie: –  Notatie : Q = R ∪ - S –  Attr(Q) = Attr(R) ∪ - Attr(S) •  ( alleen gemeenschappelijke attributen blijven behouden ) 51
  • 52. voorbeelden van queries –  Q 1: •  Retrieve the name and address of all employees who work for the ‘Research’ department RESEARCH_DEPT ← σ DNAME = Research ( DEPARTMENT ) RESEARCH_EMPS ← ( RESEARCH_DEPT wv Dnumber = Dno EMPLOYEE ) RESULT ← π Fname, Lname, Address ( RESEARCH_EMPS ) 52
  • 53. voorbeelden van queries –  Q 3: •  Find the names of employees who work on all the projects controlled by department number 5 DEPT5_PROJS ( Pno ) ← π Pnumber (σ Dnum = 5 ( PROJECT ) ) EMP_PROJ ( Ssn, Pno ) ← π Essn, Pno ( WORKS_ON ) RESULT_EMP_SSNS ← EMP_PROJ ÷ DEPT5_PROJS RESULT ← π Lname, Fname ( RESULT_EMP_SSNS Ú EMPLOYEE ) 53
  • 54. voorbeelden van queries –  Q 4: •  Make a list of projects that involve an employee whose last name is ‘Smith’, either as a worker or as a manager of the department that controls the project SMITHS (Essn) ← π SSN (σ Lname = Smith ( EMPLOYEE ) ) SMITH_WORKER_PROJ ← π Pno ( WORKS_ON Ú SMITHS ) MGRS ← π Lname, Dnumber (EMPLOYEE wv Ssn = Mgr_ssn DEPARTMENT) SMITH_MANAGED_DEPTS (Dnum) ← π Dnumber (σ Lname = Smith (MGRS) ) SMITH_MGR_PROJS (Pno) ← π Pnumber ( SMITH_MANAGED_DEPTS Ú PROJECT ) RESULT ← (SMITH_WORKER_PROJ ∪ SMITH_MGR_PROJS ) 54
  • 55. voorbeelden van queries •  Q 5: –  List the names of all employees with two or more dependents T1 (Ssn, No_of_dependents) ← EssnFCOUNT Dependent_name (DEPENDENT) T2 ← σ No_of_dependents ≥ 2 ( T1 ) RESULT ← π Lname, Fname ( T2 Ú EMPLOYEE ) 55
  • 56. voorbeelden van queries •  Q 6: –  Retrieve the names of employees who have no dependents ALL_EMPS ← π Ssn ( EMPLOYEE ) EMPS_WITH_DEPS ( Ssn ) ← π Essn ( DEPENDENT ) EMPS_WITHOUT_DEPS ← ALL_EMPS EMPS_WITH_DEPS RESULT ← π Lname, Fname ( EMPS_WITHOUT_DEPS Ú EMPLOYEE ) 56
  • 57. voorbeelden van queries –  Q 7: •  List the names of managers who have at least one dependent MGS ( Ssn ) ← π Mgr_ssn ( DEPARTMENT ) EMPS_WITH_DEPS ( Ssn ) ← π Essn ( DEPENDENT ) MGRS_WITH_DEPS ← MGRS ∩ EMPS_WITH_DEPS RESULT ← π Lname, Fname ( MGRS_WITH_DEPS Ú EMPLOYEE ) 57
  • 58. VRAGEN? 58