Guest User

Untitled

a guest
Oct 14th, 2019
155
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # BDD Récupérer des informations avec SELECT
  2.  
  3. ### Récupère tous les champs pour les sorciers nés entre 1975 et 1985
  4.  
  5. mysql> SELECT * FROM wizard WHERE birthday BETWEEN '1975-01-01' AND '1985-12-31';
  6. +----+-----------+----------+------------+-------------+---------------------------------------+-----------+
  7. | id | firstname | lastname | birthday | birth_place | biography | is_muggle |
  8. +----+-----------+----------+------------+-------------+---------------------------------------+-----------+
  9. | 1 | harry | potter | 1980-07-31 | london | | 0 |
  10. | 2 | hermione | granger | 1979-09-19 | | Friend of Harry Potter | 0 |
  11. | 4 | ron | weasley | 1980-03-01 | | Best friend of Harry | 0 |
  12. | 5 | ginny | weasley | 1981-08-11 | | Sister of Ron and girlfriend of Harry | 0 |
  13. | 6 | fred | weasley | 1978-04-01 | | | 0 |
  14. | 7 | george | weasley | 1978-04-01 | | | 0 |
  15. | 10 | drago | malefoy | 1980-06-05 | | | 0 |
  16. | 14 | dudley | dursley | 1980-06-23 | | Cousin d'Harry | 1 |
  17. +----+-----------+----------+------------+-------------+---------------------------------------+-----------+
  18. 8 rows in set (0.00 sec)
  19.  
  20. ### Le prénom uniquement des sorciers dont le prénom commence par la lettre ‘H’
  21.  
  22. mysql> SELECT firstname FROM wizard WHERE firstname LIKE 'H%';
  23. +-----------+
  24. | firstname |
  25. +-----------+
  26. | harry |
  27. | hermione |
  28. +-----------+
  29. 2 rows in set (0.00 sec)
  30.  
  31. ### Les prénom et nom de tous les membres de la famille ‘Potter’, classés par ordre de prénom
  32.  
  33. mysql> SELECT firstname, lastname FROM wizard WHERE lastname='Potter' ORDER BY firstname;
  34. +-----------+----------+
  35. | firstname | lastname |
  36. +-----------+----------+
  37. | harry | potter |
  38. | lily | potter |
  39. +-----------+----------+
  40. 2 rows in set (0.00 sec)
  41.  
  42. ### Le prénom, nom et date de naissance du plus vieux sorcier (doit fonctionner quelque soit le contenu de la table)
  43.  
  44. mysql> SELECT firstname, lastname, birthday FROM wizard ORDER BY birthday LIMIT 0,1;
  45. +-----------+------------+------------+
  46. | firstname | lastname | birthday |
  47. +-----------+------------+------------+
  48. | albus | dumbledore | 1881-07-01 |
  49. +-----------+------------+------------+
  50. 1 row in set (0.00 sec)
RAW Paste Data