Index Suivant

1   Langages de Requêtes

Soit les tables relationnelles suivantes :
Chansons(titre, compositeur)

Interpretations(no, titre, interprete)
Ecrivez les requêtes suivantes dans les langages indiqués (pour les requêtes en calcul relationnel vous pouvez choisir entre le calcul n-uplet ou le calcul domaine) :
  1. Les noms des interprêtes de chansons de Serge Gainsbourgh (algebre, calcul, SQL).

    Solution:
    
    select interprete
      from Interpretations, Chansons
     where Interpretations.titre = Chansons.titre
       and compositeur = 'Serge Gainsbourgh'
    
  2. Les titres des chansons avec plusieurs interprêtes (algebre, SQL).

    Solution:
    
    select titre
      from Interpretations A, Interpretations B
     where A.titre = B.titre
       and A.interprete <> B.interprete
    
  3. Les titres des disques avec un seul interprête (calcul, SQL).

    Solution:
    {D | $ C1, I1: Interpretations(D,C1,I1) Ù$C2, I2: Interpretations(D, C2, I2) Ù I1 <> I2)}
    
    select disque
      from Interpretations A
     where not exists (select *
                         from Interpretations B
                        where A.disque = B.disque
                          and A.interprete <> B.interprete)
    
  4. Les compositeurs qui interprêtent leurs chansons (calcul, SQL).

    Solution:
    
    select compositeur
      from Interpretations, Chansons
     where Interpretations.titre = Chansons.titre
       and compositeur = interprete
    
  5. Les compositeurs dont les chansons sont interprêtées par d'autres artistes (algebre, SQL).

    Solution:
    pcompositeur(scompositeur<>interprete(Chansons |><| Interpretations))
    
    select distinct compositeur
      from Chansons, Interpretations
     where Chansons.titre = Interpretations.titre
       and compositeur <> interprete
    
  6. Les chansons pour lesquelles il n'existe pas d'interprétation par leur compositeur (calcul, SQL).
    {T| $ C : Chansons(T,C) Ù$D : Interpretations(D,T,C) }

    Solution:
    
    select titre
      from Chansons
     where not exists (select *
                         from Interpretations
                        where Chansons.titre = Interpretations.chanson
                          and compositeur = interprete)
    
  7. Le nombre de d'interprétations de chansons de Serge Gainsbourgh (SQL).

    Solution: select count(*) from Interpretations, Chansons where Chansons.titre = Interpretations.titre and Chansons.compositeur = 'Serge Gainsbourgh'
  8. Les chansons avec plus que 20 interprétations différentes (SQL).

    Solution:
    
    select titre
      from Interpretations
    group by titre
    having count(*) > 20
    
  9. Les chansons avec le plus d'interprétations différentes (SQL).

    Solution:
    
    select titre
      from Interpretations
    group by titre
    having count(*) = (select max(count(*))
                         from Interpretations
                        group by titre)
    

Index Suivant