Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Atelier - Opérateurs ensemblistes

APERTO-NOTA

Atelier : Utilisation des opérateurs ensemblistes

1. Trouver les produits non commandés par les clients parisiens

Solution to Exercise #
SELECT ref_produit FROM produits
EXCEPT
SELECT ref_produit
FROM details_commandes dc
JOIN commandes cmd ON dc.no_commande = cmd.no_commande
JOIN clients cl ON cmd.code_client = cl.code_client
WHERE ville = 'paris';

2. Combiner les clients et les fournisseurs

Solution to Exercise #
SELECT 
    societe, 
    adresse, 
    ville 
FROM 
    clients 
UNION
SELECT 
    societe, 
    adresse, 
    ville 
FROM 
    fournisseurs
ORDER BY 
    societe;

3. Trouver les commandes avec des produits spécifiques

Solution to Exercise #
SELECT 
    no_commande 
FROM 
    details_commandes dc
JOIN 
    produits p ON dc.ref_produit = p.ref_produit
WHERE 
    code_categorie = 1 
    AND no_fournisseur = 1
INTERSECT
SELECT 
    no_commande 
FROM 
    details_commandes dc
JOIN 
    produits p ON dc.ref_produit = p.ref_produit
WHERE 
    code_categorie = 2 
    AND no_fournisseur = 2;

4. Trouver les produits non commandés par les clients d’une ville spécifique

Solution to Exercise #
SELECT ref_produit FROM produits
EXCEPT
SELECT ref_produit
FROM details_commandes dc
JOIN commandes cmd ON dc.no_commande = cmd.no_commande
JOIN clients cl ON cmd.code_client = cl.code_client
WHERE ville = 'ville';

5. Trouver les commandes avec des produits de plusieurs catégories

Solution to Exercise #
SELECT 
    no_commande 
FROM 
    details_commandes dc
JOIN 
    produits p ON dc.ref_produit = p.ref_produit
WHERE 
    code_categorie = **catégorie1**
INTERSECT
SELECT 
    no_commande 
FROM 
    details_commandes dc
JOIN 
    produits p ON dc.ref_produit = p.ref_produit
WHERE 
    code_categorie = **catégorie2**;