Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- select LTRIM(Right(UPPER(Nom), 3)) From Client;
- select Prénom, UPPER(Nom) as 'Super nom' From Client;
- select LEFT(Nom, 4), LOWER(REVERSE(Prénom)) From Client;
- select DAY(datecommande), MONTH(datecommande), YEAR(datecommande) From Commande;
- select CASE Prénom WHEN 'Luc' THEN 'Oui' ELSE 'non' from Client;
- SELECT Prénom, Nom as 'Nom de naissance' from Client;
- SELECT case sexe when 'M' then 'Monsieur' else 'Madame' end as Civilité,
- Prénom, nom,
- Prénom + ' ' + Nom as libellé
- From Client;
- SELECT case sexe when 'M' then 'Monsieur' else 'Madame' end as Civilité,
- Prénom, nom,
- Prénom + ' ' + Nom as libellé
- From Client Order by Prénom asc, Nom desc;
- select *, DATEDIFF(YYYY, datecommande, GETDATE()) From Commande;
- select * From LigneCommande;
- select * From Adresse;
- select * From Boutique;
- select * From Employé;
- select * From Commune;
- select * From Stock;
- select * From Pays;
- select * From Produit;
- select * From Marque;
- select * From Catégorie;
- select Nom, Prénom FROM Employé;
- -- 9:
- SELECT Sexe, count(*) From Client Group by Sexe;
- -- 10:
- Select count(*), CommuneId from Adresse group by CommuneId;
- -- 11:
- Select Max(PrixUnitaire) From Produit;
- -- 12:
- Select AVG(PrixUnitaire), Couleur From Produit group by Couleur;
- -- 13:
- Select DISTINCT(TauxTva) From Produit;
- -- 14:
- Select Max(Poids) From Produit;
- Select count(*) From Produit group by MarqueId;
- -- 15:
- Select count(*) as 'nombre de commande par journéee', DateCommande From Commande group by DateCommande;
- -- 16:
- Select count(*) as 'nombre de commande' From Commande Group by BoutiqueId, ClientId;
- -- 17:
- Select count(*) From Commune Group by PaysId, LEFT(CodePostal, 2) Order by PaysId, LEFT(CodePostal, 2);
- Select PaysId, Left(codepostal, 2) as Dept, count(*) As Nbr
- From Commune
- group by PaysId, Left(codepostal, 2)
- order by PaysId, Dept;
- select distinct YEAR(datecommande) as Année, Month(datecommande) as mois from commande
- select distinct TauxTva from produit;
- select distinct Couleur from produit Group by Couleur;
- select distinct count(*), Couleur from produit Group by Couleur;
- select count(distinct couleur) from produit;
- select top 3 * From Commande order by DateCommande desc;
- -- 23:
- select * From Produit Where Couleur = 'Rouge';
- -- 25:
- select top 3 * From Produit Where TauxTva < 0.20;
- -- 26
- select Libellé as 'Commune' From Commune Where Left(codepostal, 2) = 54 order by Libellé;
- -- 27
- select * From Employé Where ResponsableId IS NULL;
- -- 28
- select * From Employé Where Prénom like 'J%' AND Nom like 'B%';
- select Prénom, Nom from employé where LEFT(Prénom, 1) + left(Nom, 1) = 'JB';
- -- 29
- select * from Produit Where Couleur <> 'Gris';
- -- 30
- select * from Commande Where DateCommande between '2017-08-17' AND '2019-01-01'
- order by DateCommande desc;
- -- 31
- -- (a or b) and (not (a or b)
- -- 31
- select * from Produit where Couleur = 'Rouge' Or TauxTva < 0.15;
- -- 32
- select * From Commande where DateCommande < '2017-08-17' or DateCommande > '2019-01-01';
- select * From Commande where DateCommande not between '17-08-2019' and '01-01-2019'
- -- 33
- select * from Produit where (Couleur <> 'Rouge' and PrixUnitaire >= 100) or (SeuilRéapprovisionnement > 24) order by Couleur;
- -- 34
- select top 100 * From Commune Where (CodePostal like '54%') and (Libellé NOT like '%tte' OR Libellé like 'b%');
- --35
- select * From Produit Where (Couleur = 'Gris' or TauxTva = 0.20) AND NOT (Couleur = 'Gris' and TauxTva = 0.20)
- or Couleur <> 'Noir' and (SeuilRéapprovisionnement = 8 or SeuilRéapprovisionnement > 22);
- select * From Produit where ((Couleur = 'Gris' or TauxTva = 0.2) and (not (Couleur = 'Gris' and TauxTva = 0.20)))
- or (Couleur <> 'Noir' and ((SeuilRéapprovisionnement = 8) or (SeuilRéapprovisionnement > 22)))
- select * From Produit WHERE
- (
- CASE
- WHEN (Couleur = 'Gris') THEN 1
- ELSE 0
- END
- ^
- CASE
- WHEN (TauxTva = 0.2) THEN 1
- ELSE 0
- END
- ) = 1 or (Couleur <> 'Noir' and ((SeuilRéapprovisionnement = 8) or (SeuilRéapprovisionnement > 22)))
- order by id;
- -- 36
- select Couleur, AVG(PrixUnitaire) as 'Prix Unitaire' From Produit Group by Couleur Having AVG(PrixUnitaire) <= 60 or AVG(PrixUnitaire) > 96;
- -- 37
- select top 6 ClientId, count(*) as NbCommande from Commande where YEAR(datecommande) < 2019 group by ClientId Having count(*) >= 2 order by NbCommande desc
- -- 38
- select * from Client where Nom IN ('Barr', 'Carey', 'Reno') or Prenom IN ('Jean', 'Rosana');
- -- 39
- select * from Produit where CatégorieId IN (3, 4, 5) Order by CatégorieId, Libellé;
- -- 40
- select Libellé from Produit Where MarqueId in (
- select id from Marque where Libellé like '%ASUS%' or Libellé like '%Intel%'
- )
- -- 41
- select MarqueId, Count(*) as Nbr, AVG(PrixUnitaire), MAX(PrixUnitaire), MIN(PrixUnitaire) From Produit where CatégorieId in (
- Select distinct id From Catégorie where Libellé like '%Carte mère%' or Libellé like '%Carte Graphique%'
- ) or (Couleur = 'Noir' and Poids < 1) group by MarqueId Order by MarqueId;
- -- 42
- select DISTINCT Libellé From Pays where id IN (
- Select PaysFabricationId from Produit
- )
- -- 43
- select * From Produit Where PrixUnitaire IN (
- Select Max(PrixUnitaire) From Produit where Couleur = 'Noir'
- ) and Couleur = 'Noir';
- -- 44
- select *
- from produit
- where PrixUnitaire > (
- select avg(prixunitaire)
- from Produit
- where marqueid in
- (
- select distinct id
- from marque
- where libelle in ('Corsair', 'Samsung')
- )
- )
- and couleur = 'Gris'
- and poids > 0.5;
- -- 45
- select * from Client c
- where exists (
- select o.clientid, count(*)
- from Commande o
- where year(datecommande) < 2019
- and o.ClientId = c.Id
- group by ClientId
- having count(*) > 2
- )
- order by Nom, Prénom
- select * from Client
- where exists (
- select Commande.clientid, count(*)
- from Commande
- where year(datecommande) < 2019
- and Commande.ClientId = Client.Id
- group by ClientId
- having count(*) > 2
- )
- order by Nom, Prénom
- -- 46
- select * from Produit where Id >= ANY (
- select DISTINCT ProduitId from LigneCommande where Quantité > 5
- )
- -- 47
- select *
- from produit
- where PrixUnitaire > all (
- select avg(PrixUnitaire) as PrixMoy
- from Produit
- group by catégorieId
- )
- order by Libellé
- -- 48
- select Id, Nom, Prénom From Employé
- UNION
- select Id, Nom, Prénom From Client Order by Nom, Prénom;
- -- 49
- select * from Produit where Id = ANY (
- select DISTINCT ProduitId from LigneCommande where Quantité > 5
- )
- UNION
- select * from Produit where Id = ANY (
- select DISTINCT ProduitId from Stock
- )
- select * From Catégorie, Marque
- select * from Produit p
- inner join catégorie c on c.id = p.catégorieId;
- -- 50
- select MarqueId, m.Libellé as 'Libellé Marque', m.Id as 'Id Produit', p.Libellé as 'Libellé Produit'
- from Produit p
- inner join Marque m on m.id = p.MarqueId Order by m.Libellé, p.Libellé;
- -- 51
- select y.Id as IdPays, y.Libellé as Pays, m.Id as IdMarque, m.Libellé as Marque, p.Id as ProdId, p.Libellé as Produit
- from Produit p
- join Marque m on m.Id = p.CatégorieId
- join Pays y on y.Id = p.PaysFabricationId
- order by y.Libellé, m.Libellé, p.Libellé;
- -- 52
- select c.Libellé as Catégorie, p.Id, p.Libellé as Produit, p.PrixUnitaire
- from Produit p
- inner join (
- select CatégorieId, MAX(prixunitaire) as MAXPrix
- from produit
- group by CatégorieId
- ) x on x.CatégorieId = p.CatégorieId and p.PrixUnitaire = x.MAxPrix
- join Catégorie c on c.Id = p.CatégorieId order by c.Libellé, p.Libellé;
- select CatégorieId, MAX(prixunitaire) as MAXPrix
- from produit
- group by CatégorieId
- -- 53
- select c.Libellé, c.Id as 'Catégorie Id', p.Libellé as 'Libellé Produit', p.PrixUnitaire from Produit p
- left join Stock s on p.Id = NULL
- inner join Catégorie c on CatégorieId = c.Id
- order by p.Libellé, c.Libellé;
- select c.Libellé as Catégorie, p.Id as ProdId, p.Libellé as Produit, PrixUnitaire
- from Produit p
- join Catégorie c on c.Id = p.CatégorieId
- left join Stock s on s.ProduitId = p.Id
- where s.ProduitId is null
- order by c.Libellé, p.Libellé;
- -- 54
- select e.Id as EmpId, e.Prénom as EmplPrénom, e.Nom as EmplNom,
- Case when e.ResponsableId is null then 'Cadre' else 'Employé' end as Poste,
- r.Id as RespId, r.Nom as RespNom, r.Prénom as RespPrénom,
- b.Id as BoutId, b.Libellé as Boutique
- from Employé e
- left join Boutique b on b.Id = e.boutiqueId
- left join Employé r on r.Id = e.ResponsableId
- order by Poste, e.Nom, e.Prénom;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement