Advertisement
kuji89

Untitled

Jun 18th, 2019
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MySQL 8.44 KB | None | 0 0
  1. select LTRIM(Right(UPPER(Nom), 3)) From Client;
  2.  
  3. select Prénom, UPPER(Nom) as 'Super nom' From Client;
  4. select LEFT(Nom, 4), LOWER(REVERSE(Prénom)) From Client;
  5. select DAY(datecommande), MONTH(datecommande), YEAR(datecommande) From Commande;
  6. select CASE Prénom WHEN 'Luc' THEN 'Oui' ELSE 'non' from Client;
  7.  
  8. SELECT Prénom, Nom as 'Nom de naissance' from Client;
  9.  
  10. SELECT case sexe when 'M' then 'Monsieur' else 'Madame' end as Civilité,
  11. Prénom, nom,
  12. Prénom + ' ' + Nom as libellé
  13. From Client;
  14.  
  15. SELECT case sexe when 'M' then 'Monsieur' else 'Madame' end as Civilité,
  16. Prénom, nom,
  17. Prénom + ' ' + Nom as libellé
  18. From Client Order by Prénom asc, Nom desc;
  19.  
  20.  
  21.  
  22.  
  23. select *, DATEDIFF(YYYY, datecommande, GETDATE()) From Commande;
  24. select * From LigneCommande;
  25. select * From Adresse;
  26. select * From Boutique;
  27. select * From Employé;
  28. select * From Commune;
  29. select * From Stock;
  30. select * From Pays;
  31. select * From Produit;
  32. select * From Marque;
  33. select * From Catégorie;
  34.  
  35. select Nom, Prénom FROM Employé;
  36.  
  37. -- 9:
  38. SELECT Sexe, count(*) From Client Group by Sexe;
  39. -- 10:
  40. Select count(*), CommuneId from Adresse group by CommuneId;
  41. -- 11:
  42. Select Max(PrixUnitaire) From Produit;
  43. -- 12:
  44. Select AVG(PrixUnitaire), Couleur From Produit group by Couleur;
  45. -- 13:
  46. Select DISTINCT(TauxTva) From Produit;
  47. -- 14:
  48. Select Max(Poids) From Produit;
  49. Select count(*) From Produit group by MarqueId;
  50. -- 15:
  51. Select count(*) as 'nombre de commande par journéee', DateCommande From Commande group by DateCommande;
  52. -- 16:
  53. Select count(*) as 'nombre de commande' From Commande Group by BoutiqueId, ClientId;
  54. -- 17:
  55. Select count(*) From Commune Group by PaysId, LEFT(CodePostal, 2) Order by PaysId, LEFT(CodePostal, 2);
  56.  
  57. Select PaysId, Left(codepostal, 2) as Dept, count(*) As Nbr
  58. From Commune
  59. group by PaysId, Left(codepostal, 2)
  60. order by PaysId, Dept;
  61.  
  62. select distinct YEAR(datecommande) as Année, Month(datecommande) as mois from commande
  63. select distinct TauxTva from produit;
  64. select distinct Couleur from produit Group by Couleur;
  65.  
  66. select distinct count(*), Couleur from produit Group by Couleur;
  67.  
  68. select count(distinct couleur) from produit;
  69.  
  70. select top 3 * From Commande order by DateCommande desc;
  71.  
  72. -- 23:
  73. select * From Produit Where Couleur = 'Rouge';
  74. -- 25:
  75. select top 3 * From Produit Where TauxTva < 0.20;
  76. -- 26
  77. select Libellé as 'Commune' From Commune Where Left(codepostal, 2) = 54 order by Libellé;
  78. -- 27
  79. select * From Employé Where ResponsableId IS NULL;
  80. -- 28
  81. select * From Employé Where Prénom like 'J%' AND Nom like 'B%';
  82. select Prénom, Nom from employé where LEFT(Prénom, 1) + left(Nom, 1) = 'JB';
  83. -- 29
  84. select * from Produit Where Couleur <> 'Gris';
  85. -- 30
  86. select * from Commande Where DateCommande between '2017-08-17' AND '2019-01-01'
  87. order by DateCommande desc;
  88. -- 31
  89. -- (a or b) and (not (a or b)
  90. -- 31
  91. select * from Produit where Couleur = 'Rouge' Or TauxTva < 0.15;
  92. -- 32
  93. select * From Commande where DateCommande < '2017-08-17' or DateCommande > '2019-01-01';
  94. select * From Commande where DateCommande not between '17-08-2019' and '01-01-2019'
  95. -- 33
  96. select * from Produit where (Couleur <> 'Rouge' and PrixUnitaire >= 100) or (SeuilRéapprovisionnement > 24) order by Couleur;
  97. -- 34
  98. select top 100 * From Commune Where (CodePostal like '54%') and (Libellé NOT like '%tte' OR Libellé like 'b%');
  99. --35
  100. select * From Produit Where (Couleur = 'Gris' or TauxTva = 0.20) AND NOT (Couleur = 'Gris' and TauxTva = 0.20)
  101. or Couleur <> 'Noir' and (SeuilRéapprovisionnement = 8 or SeuilRéapprovisionnement > 22);
  102.  
  103. select * From Produit where ((Couleur = 'Gris' or TauxTva = 0.2) and (not (Couleur = 'Gris' and TauxTva = 0.20)))
  104. or (Couleur <> 'Noir' and ((SeuilRéapprovisionnement = 8) or (SeuilRéapprovisionnement > 22)))
  105.  
  106. select * From Produit WHERE
  107. (
  108. CASE
  109.   WHEN (Couleur = 'Gris') THEN 1
  110.   ELSE 0
  111. END
  112. ^
  113. CASE
  114.   WHEN (TauxTva = 0.2) THEN 1
  115.   ELSE 0
  116. END
  117. ) = 1 or (Couleur <> 'Noir' and ((SeuilRéapprovisionnement = 8) or (SeuilRéapprovisionnement > 22)))
  118. order by id;
  119.  
  120.  
  121.  
  122. -- 36
  123. select Couleur, AVG(PrixUnitaire) as 'Prix Unitaire' From Produit Group by Couleur Having AVG(PrixUnitaire) <= 60 or AVG(PrixUnitaire) > 96;
  124. -- 37
  125. select top 6 ClientId, count(*) as NbCommande from Commande where YEAR(datecommande) < 2019 group by ClientId Having count(*) >= 2 order by NbCommande desc
  126. -- 38
  127. select * from Client where Nom IN ('Barr', 'Carey', 'Reno') or Prenom IN ('Jean', 'Rosana');
  128. -- 39
  129. select * from Produit where CatégorieId IN (3, 4, 5) Order by CatégorieId, Libellé;
  130. -- 40
  131. select Libellé from Produit Where MarqueId in (
  132. select id from Marque where Libellé like '%ASUS%' or Libellé like '%Intel%'
  133. )
  134. -- 41
  135. select MarqueId, Count(*) as Nbr, AVG(PrixUnitaire), MAX(PrixUnitaire), MIN(PrixUnitaire) From Produit where CatégorieId in (
  136. Select distinct id From Catégorie where Libellé like '%Carte mère%' or Libellé like '%Carte Graphique%'
  137. ) or (Couleur = 'Noir' and Poids < 1) group by MarqueId Order by MarqueId;
  138.  
  139. -- 42
  140.  
  141. select DISTINCT Libellé From Pays where id IN (
  142. Select PaysFabricationId from Produit
  143. )
  144.  
  145. -- 43
  146.  
  147. select * From Produit Where PrixUnitaire IN (
  148.     Select Max(PrixUnitaire) From Produit where Couleur = 'Noir'
  149. ) and Couleur = 'Noir';
  150.  
  151. -- 44
  152. select *
  153. from produit
  154. where PrixUnitaire > (
  155. select avg(prixunitaire)
  156. from Produit
  157. where marqueid in
  158. (
  159. select distinct id
  160. from marque
  161. where libelle in ('Corsair', 'Samsung')
  162. )
  163. )
  164. and couleur = 'Gris'
  165. and poids > 0.5;
  166.  
  167.  
  168. -- 45
  169. select * from Client c
  170. where exists (
  171.                 select o.clientid, count(*)
  172.                 from Commande o
  173.                 where year(datecommande) < 2019
  174.                 and o.ClientId = c.Id
  175.                 group by ClientId
  176.                 having count(*) > 2
  177. )
  178. order by Nom, Prénom
  179.  
  180.  
  181. select * from Client
  182. where exists (
  183.                 select Commande.clientid, count(*)
  184.                 from Commande
  185.                 where year(datecommande) < 2019
  186.                 and Commande.ClientId = Client.Id
  187.                 group by ClientId
  188.                 having count(*) > 2
  189. )
  190. order by Nom, Prénom
  191. -- 46
  192. select * from Produit where Id >= ANY (
  193.     select DISTINCT ProduitId from LigneCommande where Quantité > 5
  194. )
  195. -- 47
  196. select *
  197. from produit
  198. where PrixUnitaire > all (
  199.                             select avg(PrixUnitaire) as PrixMoy
  200.                             from Produit
  201.                             group by catégorieId
  202. )
  203. order by Libellé
  204.  
  205. -- 48
  206.  
  207. select Id, Nom, Prénom From Employé
  208. UNION
  209. select Id, Nom, Prénom From Client Order by Nom, Prénom;
  210.  
  211.  
  212. -- 49
  213. select * from Produit where Id = ANY (
  214.     select DISTINCT ProduitId from LigneCommande where Quantité > 5
  215. )
  216. UNION
  217. select * from Produit where Id = ANY (
  218.     select DISTINCT ProduitId from Stock
  219. )
  220.  
  221. select * From Catégorie, Marque
  222.  
  223. select * from Produit p
  224. inner join catégorie c on c.id = p.catégorieId;
  225.  
  226. -- 50
  227. select MarqueId, m.Libellé as 'Libellé Marque', m.Id as 'Id Produit', p.Libellé as 'Libellé Produit'
  228. from Produit p
  229. inner join Marque m on m.id = p.MarqueId Order by m.Libellé, p.Libellé;
  230.  
  231. -- 51
  232. 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
  233. from Produit p
  234. join Marque m on m.Id = p.CatégorieId
  235. join Pays y on y.Id = p.PaysFabricationId
  236. order by y.Libellé, m.Libellé, p.Libellé;
  237.  
  238. -- 52
  239. select c.Libellé as Catégorie, p.Id, p.Libellé as Produit, p.PrixUnitaire
  240. from Produit p
  241. inner join (
  242.             select CatégorieId, MAX(prixunitaire) as MAXPrix
  243.             from produit
  244.             group by CatégorieId
  245.             ) x on x.CatégorieId = p.CatégorieId and p.PrixUnitaire = x.MAxPrix
  246. join Catégorie c on c.Id = p.CatégorieId order by c.Libellé, p.Libellé;
  247.  
  248. select CatégorieId, MAX(prixunitaire) as MAXPrix
  249.             from produit
  250.             group by CatégorieId
  251.  
  252. -- 53
  253. select c.Libellé, c.Id as 'Catégorie Id', p.Libellé as 'Libellé Produit', p.PrixUnitaire from Produit p
  254. left join Stock s on p.Id = NULL
  255. inner join Catégorie c on CatégorieId = c.Id
  256. order by p.Libellé, c.Libellé;
  257.  
  258. select c.Libellé as Catégorie, p.Id as ProdId, p.Libellé as Produit, PrixUnitaire
  259. from Produit p
  260. join Catégorie c on c.Id = p.CatégorieId
  261. left join Stock s on s.ProduitId = p.Id
  262. where s.ProduitId is null
  263. order by c.Libellé, p.Libellé;
  264.  
  265. -- 54
  266. select e.Id as EmpId, e.Prénom as EmplPrénom, e.Nom as EmplNom,
  267.        Case when e.ResponsableId is null then 'Cadre' else 'Employé' end as Poste,
  268.        r.Id as RespId, r.Nom as RespNom, r.Prénom as RespPrénom,
  269.        b.Id as BoutId, b.Libellé as Boutique
  270. from Employé e
  271. left join Boutique b on b.Id = e.boutiqueId
  272. left join Employé r on r.Id = e.ResponsableId
  273. order by Poste, e.Nom, e.Prénom;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement