Advertisement
Guest User

DB SQL HW 1-6

a guest
Feb 22nd, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.41 KB | None | 0 0
  1. -- HW 1
  2. select animal_name AS 'ID', animal_age AS 'Age', arrival_date AS 'Arrival Date'
  3. from animal
  4. where animal_gender = 'F'
  5. order by 1 asc;
  6.  
  7. -- HW 2
  8. select animal_id AS 'ID', animal_name AS 'Animal Name'
  9. from animal
  10. where arrival_date = '2014-01-02';
  11.  
  12. -- HW 3
  13. select animal_id AS 'ID', animal_name AS 'animal name'
  14. from animal join breed
  15. on animal.breed_id = breed.breed_id
  16. where animal_gender = 'M' AND animal_id = 10
  17. order by animal_id asc;
  18.  
  19. -- HW 4
  20. select concat(vol_first, ' ', vol_last) AS 'Coco Volunteer'
  21. from animal join volunteer
  22. on animal.vol_id = volunteer.vol_id
  23. where animal_name = 'Coco';
  24.  
  25. -- HW 5
  26. select animal_name AS 'Name', breed_name AS 'Breed', (male_lo_weight + female_lo_weight) / 2 AS 'Average Low Weight', (male_hi_weight + female_hi_weight) / 2 AS 'Average High Weight'
  27. from animal join breed
  28. on animal.breed_id = breed.breed_id
  29. order by 4 desc;
  30.  
  31. -- HW 6 requires a 3 way join with the wishlist
  32. select concat(adopter_first, ' ', adopter_last, ' wishes for a ', breed_name, ' age ', animal_age) AS 'Wish list'
  33. from adopter join wishlist -- we joined the wishlist THIS IS A THREE-WAY JOINwishlist
  34. on adopter.adopter_id = wishlist.adopter_id
  35. join breed -- we join breed with the the breed that they want too
  36. on breed.breed_id = wishlist.desired_breed
  37. join animal
  38. on animal.breed_id = wishlist.wish_id
  39. where breed_type = 'cat'
  40. order by adopter_first asc;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement