Sie sind auf Seite 1von 5

CorrigsSQL

Soitlabasededonnesrelationnelledeschma:
U(NU,NomU,Ville)
P(NP,NomP,Couleur,Poids)
F(NF,NomF,Statut,Ville)
PUF(NP,NU,NF,Quantit)
1.Donnerlenumro,lenometlaVilledetouteslesusines
select*fromU
2.Donnerlenumro,lenometlaVilledetouteslesusinesquinesontpassituesLondres

select*fromU
whereVille'Londres'

3.Donnerlesnumrosdesfournisseursquiapprovisionnentl'usinen1enproduitn1
selectNFfromPUF
whereNU=1andNP=1
4.Donnerlenometlacouleurdesproduitslivrsparlefournisseurn1
4a

selectdistinctNomP,Couleur
fromP,PUF
wherePUF.NP=P.NPandNF=1

4b.

selectNomP,Couleur
fromP
whereNPin(selectNP
fromPUFwhereNF=1)

5.Donnerlesnumrosdesfournisseursquiapprovisionnentl'usinen1enunproduitrouge
5a.

selectdistinctNF
fromPUF,P
whereCouleur='Rouge'andPUF.NP=P.NPandNU=1

5b.

selectdistinctNFfromPUF
whereNU=1
andNPin(selectNP
fromPwhereCouleur='Rouge')

6.Donner lesnomsdesfournisseursquiapprovisionnentuneusinedeLondresoudeParisenun
produitrouge
6a.

selectNomF
fromPUF,P,F,U
whereCouleur='rouge'
andPUF.NP=P.NPandPUF.NF=F.NFandPUF.NU=U.NU
and(U.Ville='Londres'orU.Ville='Paris')

6b.

selectNomF
fromF
whereNFin

(selectNF
fromPUF
1

whereNPin

(selectNPfromP
whereCouleur='Rouge')

andNUin
(selectNUfromU
whereVille='LondresorVille='Paris'))
7.Donnerlesnumrosdesproduitslivrsuneusineparunfournisseurdelammeville

selectdistinctNP
fromPUF,F,U
wherePUF.NF=F.NFandPUF.NU=U.NUandU.Ville=F.Ville

8.DonnerlesnumrosdesproduitslivrsuneusinedeLondresparunfournisseurdeLondres.
8a.

selectdistinctNP
fromPUF,F,U
wherePUF.NF=F.NFandPUF.NU=U.NUandF.Ville=LondresandU.Ville='Londres

8b.

selectdistinctNP
fromPUF
whereNFin

andNUin

(selectNF
fromF
whereVille='Londres')
(selectNU
fromU
whereVille='Londres')

9.Donnerlesndesusinesquiontaumoinsunfournisseurquinestpasdelammeville

selectdistinctPUF.NU
fromPUF,F,U
wherePUF.NF=F.NFandPUF.NU=U.NUandU.VilleF.Ville

10.Donnerlesnumrosdesfournisseursquiapprovisionnentlafoislesusinesn1etn2
10a. selectdistinctfirst.NF
fromPUFfirst,PUFsecond
wherefirst.NF=second.NFandfirst.NU=1andsecond.NU=2
10b. selectdistinctNF
fromPUF
whereNU=2
andNFin(selectNFfromPUFwhereNU=1)

10c.(selectNFfromPUFwhereNU=1)
intersect
(selectNFfromPUFwhereNU=2)
11.Donnerlesnumrosdesusinesquiutilisentaumoinsunproduitdisponiblechezlefournisseur
numro3(leproduitnestpasncessairementlivrlusineparlefournisseurnumro3)

selectdistinctNUfromPUF
whereNPin
(selectNPfromPUF
whereNF=3)

12.Donnerlenumroduproduitlepluslger(lesnumrossiplusieursproduitsontcemmepoids)

12a. selectNP
fromP
wherePoidsin
(selectmin(Poids)fromP)
12b. selectNP
fromPp1
wherenotexists(select*
fromP
wherep1.Poids>Poids)
12c.selectNP
fromP
wherePoidsall(selectPoidsfromP)
13.Donnerlesnumrosdesusinesquinereoiventaucunproduitrougedunfournisseurlondonien

13. selectNUfromU
whereNUnotin
(selectNU
fromPUF,U,P,F
wherePUF.NP=P.NPandPUF.NF=F.NF
andCouleur='Rouge'andVille='Londres')
14.Donnerlesnumrosdesfournisseursquifournissentaumoinsunproduitfourniparaumoinsun
fournisseurquifournitaumoinsunproduitrouge
14a. selectdistinctpuf.NF
fromPUFpuf,PUFpuf1,PUFpuf2,P
wherecouleur='rouge'
andP.NP=puf2.NPandpuf2.NF=puf1.NFandpuf1.NP=puf.NP
14b. selectdistinctNFfromPUF
whereNPin
(selectNP
fromPUF
whereNFin

(selectNF
fromPUF
whereNPin

(selectNP
fromP
whereCouleur='rouge')))

15. Donner tous les triplets (Ville f, NP, Ville u) telle quun fournisseur de la premire ville
approvisionneuneusinedeladeuximevilleavecunproduitNP

selectdistinctF.Ville,NP,U.Ville
fromPUF,U,F
wherePUF.NF=F.NFandPUF.NU=U.NU

16. Donner tous les triplets (Ville f, NP, Ville u) telle quun fournisseur de la premire ville
approvisionneuneusinedeladeuximevilleavecunproduitNPmaissanslestripletsolesdeux
villessontidentiques

selectdistinctF.Ville,NP,U.Ville

fromPUF,U,F
whereF.VilleU.VilleandPUF.NF=F.NFandPUF.NU=U.NU
17.DonnerlesnumrosdesproduitsquisontlivrstouteslesusinesdeLondres

selectNPfromP
wherenotexists(selectNU
fromU
whereVille='Londres'
andnotexists(select*fromPUF
whereP.NP=PUF.NPandU.NU=PUF.NU)
)
)
Note:Pour tout NP slectionn, il nexiste pas dusine Londres pour laquelle ilnexiste pas de
produitNPlivr.
18.Donnerlesndesfournisseursquiapprovisionnenttouteslesusinesavecunmmeproduit

selectNFfromF
whereexists
(selectNP
fromP
wherenotexists
(selectNU
fromU
wherenotexists
(select*
fromPUF
whereF.NF=PUF.NF
andU.NU=PUF.NU
andP.NP=PUF.NP)
)
)

Note:Pourtoutfournisseurslectionn,ilnexistepasdusinequinesontpaslivresenproduitNP
dufournisseurnf.
20.Donnerlesnumrosdesusinesquis'approvisionnentuniquementchezlefournisseurnumro3

selectNUfromU
whereNUnotin(selectNU
fromPUF
whereNF3)

21.Ajouterunnouveaufournisseur:45,Alfred,soustraitant,Chalon.
insertintoF:<45,Alfred,soustraitant,Chalon>
22.Supprimertouslesproduitsdecouleurnoireetdenumrocomprisentre100et199
deletePwhereNP100andNP199andcouleur='noire'
23.ChangerlaVilledufournisseurnumro1,iladmnagpourNice

updateF:setVille='Nice'
whereNF=1
23.ChangerlestatutdetouslesfournisseursdeParisetdeLyonensoustraitant

updateFsetstatut='soustraitant'
whereVille='Paris'orVille='Lyon'

24.Donnerlenombredusinesclientesdufournisseurnumro1

selectcount(distinctNU)
fromPUF
whereNF=1

26.Pourchaqueproduitetchaqueusinelaquelleilatlivr,donnerlenumrodeproduit,lusine
etlaquantittotalequiatlivre
26.

selectNP,NU,sum(Quantite)
fromPUF
groupbyNP,NU

Das könnte Ihnen auch gefallen