La base de données suivante permet de gérer les résultats des courses de Formule 1 dans un championnat.
CHAMPIONNAT(#nom:string, annee:integer)
CIRCUIT(#nom:string, ville:string)
COURSE(#nom:string,circuit=>CIRCUIT(nom), championnat=>CHAMPIONNAT(nom))
SPONSOR(#nom:string)
ECURIE(#nom:string, devise:string, couleur:string, sponsor=>SPONSOR(nom))
PILOTE(#id:integer, nom:string, prenom:string, ecurie=>ECURIE(nom))
TOUR(#pilote => PILOTE(id), #course => COURSE(nom), #num:integer, duree:integer)
En algèbre relationnel et en SQL, afficher la liste de tous les pilotes dont le nom commence par la lettre 'D'.
R1 = Restriction(PILOTE, nom COMME 'D%')
R = Projection(R1, nom, prenom)
SELECT nom, prenom
FROM PILOTE P
WHERE P.nom LIKE 'D%' ;
En SQL, afficher le nombre de pilotes par écurie en classant les résultats par ordre alphabétique des noms des écuries.
SELECT P.ecurie, COUNT(P.nom) AS nb_pilotes
FROM PILOTE P
GROUP BY P.ecurie
ORDER BY P.ecurie ;
En algèbre relationnel et en SQL, afficher les noms des sponsors qui ne sont pas liés à une écurie.
R1 = JointureExterneGauche(SPONSOR, ECURIE, SPONSOR.nom = ECURIE.sponsor)
R2 = Restriction(R1, ECURIE.nom = NULL)
R = Projection(R2, SPONSOR.nom)
SELECT S.nom
FROM SPONSOR S LEFT JOIN ECURIE E ON S.nom = E.sponsor
WHERE E.nom IS NULL ;
En SQL, afficher le numéro, nom, prénom et écurie, avec leur temps moyen par tour, des pilotes participant à la course Daytonutc 500
; mais en ne conservant que les pilotes qui ont effectués au moins deux tours de piste, et en classant le résultat par temps moyen décroissant.
SELECT T.pilote, P.nom, P.prenom, P.ecurie, AVG(T.duree) AS moyenne
FROM TOUR T, PILOTE P
WHERE T.pilote = P.id
AND T.course = 'Daytonutc 500'
GROUP BY T.pilote, P.nom, P.prenom, P.ecurie
HAVING COUNT(T.num) > 1
ORDER BY moyenne DESC ;