Vous êtes sur la page 1sur 6

soit le schéma relationnel suivant :

article(code_art, designation, qte_stock, prix)


client(code_client,designation,adresse)
commande(num_cde,date_cde,#code_client)
detail_cde(#num_cde,#code_art,qte_cde)
livraison(num_liv,date_liv,#num_cde)
detail_liv(#num_liv,#code_art,qte_liv)
/*********************************************/
Abonne(num_ab, nom, prenom, adresse)
Livre (cote, titre, année_edition)
Auteur (num_auteur, nom, prenom, nationalite)
Ecrire (#num_auteur,#cote)
Emprunter (#num_ab,#cote, date_debut, date_retour)

1. determiner les clients qui ont passé des commandes durant l'année 2020

2. determiner les clients qui n'ont pas passé des commandes durant l'année 2020

3. determiner les articles jamais commandés

4. determiner le montant de la commande 125

5. determiner pour chaque commande son montant

6. determiner les numeros de commande ayant un montant > 2500

7. determiner la (les) commande ayant le plus grand montant

8. determiner pour chaque commande le nombre d'articles qu'elle contient

9. determiner le CA réalisé durant l'année 2020

10. determine la (les) commandes contenant la totalité des articles.

1. select client.code_client,designation from client ,commande where


client.code_client=commande.code_client and date_cde between '01/01/2020' and
'21/12/2020';
select code_client from commande where date_cde between '01/01/2020' and '21/12/2020';

2.

select code client from client

minus

select code_client from commande where date_cde between '01/01/2020' and '21/12/2020';

select code_client,designation from client

where code_client NOT IN ( select code_client from commande where date_cde between
'01/01/2020' and '21/12/2020');

3.

select code_art,designation from article

where code_art not in (

select code_art from detail_cde);

select code_art from article

minus

select code_art from detail_cde;

4.

select sum(qte_cde*prix) montant

from article a,detail_cde d

where a.code_art=d.code_art and num_cde=125;

5.

select sum(qte_cde*prix) montant

from article a,detail_cde d

where a.code_art=d.code_art
group by num_cde;

select num_cde,sum(qte_cde*prix) montant

from article a,detail_cde d

where a.code_art=d.code_art

group by num_cde;

6.

syntaxe d'une requete Select

1.select listecolonnes[,fonctions] 5

2.from listetables 1

3.[where condition] 2

4.[group by listecolonnes] 3

5.[having condition] 4

6.[order by liste colonnes ASC|DESC]; 6

select num_cde,sum(qte_cde*prix) montant

from article a,detail_cde d

where a.code_art=d.code_art

group by num_cde

having sum(qte_cde*prix)>2500;

7.

select num_cde from

(select num_cde, sum(qte_cde*prix) montant

from article a,detail_cde d

where a.code_art=d.code_art

group by num_cde) S1

where s1.montant=select max(montant) from


(select num_cde, sum(qte_cde*prix) montant

from article a,detail_cde d

where a.code_art=d.code_art

group by num_cde) S2;

create view v_cde as (select num_cde, sum(qte_cde*prix) montant

from article a,detail_cde d

where a.code_art=d.code_art

group by num_cde);

select * from v_cde;

select num_cde from v_cde

where montant=select max(montant) from v_cde;

select num_cde, sum(qte_cde*prix) montant

from article a,detail_cde d

where a.code_art=d.code_art

group by num_cde

having sum(qte_cde*prix)=(select sum(qte_cde*prix) montant

from article a,detail_cde d

where a.code_art=d.code_art

group by num_cde

order by montant DESC

limit 1);

requêtes imbriquée

select listecolonnes

from listetables

where [colonne][op logique][op SQL] (select listecolonnes from listetables


where [colonne][op logique][op SQL] (select
listecolonnes from listetables

where ...))

sous requete monoligne : operateur logique =, >, >=,<, <= et <>

sous requete multiligne : operateur SQL in, not in, exists, not exists, any et all

select num_cde, sum(qte_cde*prix) montant

from article a,detail_cde d

where a.code_art=d.code_art

group by num_cde

having sum(qte_cde*prix)>=all(select sum(qte_cde*prix) montant

from article a,detail_cde d

where a.code_art=d.code_art

group by num_cde

);

select num_cde, sum(qte_cde*prix) montant

from article a,detail_cde d

where a.code_art=d.code_art

group by num_cde

having sum(qte_cde*prix) >= all (select sum(qte_cde*prix)

from article a,detail_cde d

where a.code_art=d.code_art

group by num_cde);

8.

select num_cde, count(*) from

detail_cde dc
group by num_cde;

9.

select sum(qte_cde*prix) CA

from article a,detail_cde d,commande c

where a.code_art=d.code_art

and c.num_cde=d.num_cde

and date_cde between '01/01/2020' and '31/12/2020';

10.

select num_cde, count(*) from

detail_cde dc

group by num_cde

having count(*) = (select count(*) from article);

/************************************/

Déterminer les abonnés qui ont emprunté tous les livres

Vous aimerez peut-être aussi