Guest User

Untitled

a guest
Apr 24th, 2014
2,481
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.51 KB | None | 0 0
  1. /*
  2. 1.) For every boat, list the marina number, slip number, boat name, owner number, owner's first anme, and owner's last name. (11 rows)
  3. */
  4. select marina_num, slip_num, boat_name, owner.owner_num, first_name,last_name
  5. from marina_slip,owner
  6. where marina_slip.owner_num=owner.owner_num;
  7.  
  8.  
  9. /*
  10. 2.) For every completed or open service request for routine engine maintenance, list the slip ID, description, and status. (1 row)
  11. */
  12. select slip_id,description, status
  13. from service_request, service_category
  14. where service_request.category_num= service_category.category_num and category_description= 'routine engine maintenance';
  15. /*
  16. 3.)For every service request for routine engine maintenance, list the slip ID, marina number, slip number, estimated hours, spent hours, owner number, and owner's last name. (1 row)
  17. */
  18.  
  19. /*
  20. 4.)List the first and last names of all onwers who have a boat in a 40-foot slip, use the IN operator in your formulation. (5 rows)
  21. */
  22. select first_name, last_name from owner where owner_num in (select owner_num from marina_slip where length = '40');
  23. /*
  24. 5.)Repeat number 4, but this time use the EXISTS operator in your formulation. (5 rows)
  25. */
  26. select last_name, first_name
  27. from owner
  28. where exists
  29. (select * from marina_slip where marina_slip.owner_num= owner.owner_num and length ='40');
  30. /*
  31. 6.) List the names of any pair of boats that have the same type. For example one pair would be Anderson Iland Escape, because the boat type for both boats is Sprite 4000. The first name listed should be the major sort key and the second name should be the minor sort key. (4 rows)
  32. */
  33. select x.boat_name, y.boat_name, x.boat_type
  34. from marina_slip x, marina_slip y
  35. where x.boat_type=y.boat_type and x.boat_name < y.boat_name;
  36. /*
  37. 7.) List the boat name, owner number, owner last name, and owner first name for each boat in marina 1. (5 rows)
  38. */
  39. select boat_name, owner.owner_num, last_name, first_name
  40. from marina_slip,owner
  41. where marina_slip.owner_num=owner.owner_num and marina_num =1;
  42.  
  43. /*
  44. 8.)Repeat number 7, but this time only lists boats in 30-foot slips. (2 rows)
  45. */
  46. select boat_name, owner.owner_num,last_name, first_name
  47. from marina_slip, owner
  48. where marina_slip.owner_num= owner.owner_num and marina_num = 1 and length =30;
  49. /*
  50. 9.)List the marina number, slip number, and boat name for boats whose owners live in Glander Bay or whose type is Sprite 4000. (4 rows)
  51. */
  52. select marina_num, slip_num,boat_name
  53. from marina_slip,owner
  54. where marina_slip.owner_num= owner.owner_num and city= 'Glander Bay'
  55. Union
  56. select marina_num, slip_num, boat_name
  57. from marina_slip
  58. where boat_type='Sprite 4000';
  59. /*
  60. 10.) List the marina number, slip number, and boat name for boats whose owners live in Glander Bay and whose type is Sprite 4000. (2 rows)
  61. */
  62. select marina_num,slip_num,boat_name,owner.owner_num
  63. from marina_slip,owner
  64. where marina_slip.owner_num = owner.owner_num
  65. and city= 'Glander Bay';
  66. /*
  67. 11.) List the marina number, slip number, and boat name for boats whose owners live in Glander Bay but whose type is not Sprite 4000. (1 row)
  68. */
  69. /*
  70.  
  71. 12.)Find the service ID and slip ID for each service request whose estimated hours is greater than the number of estimated hours of at least one service request on which the category number is 3. (13 rows)
  72. */
  73. select service_id, slip_id
  74. from service_request
  75. where est_hours > any (select est_hours from service_request where category_num =3);
  76. /*
  77. 13.)Find the service ID and slip ID for each service request whose estimated hours is greater than the number of estimated hours on every service request on which the category number is 3. (5 rows)
  78. */
  79. select service_id, slip_id
  80. from service_request
  81. where est_hours > all (select est_hours from service_request where category_num =3);
  82. /*
  83. 14.) List the slip ID, boat name, owner number, service ID, number of estimated hours, and number of spent hours for each service request on which the category number is 2. (4 rows)
  84. */
  85. select marina_slip.slip_id, boat_name,owner_num,service_id,est_hours,spent_hours
  86. from service_request, marina_slip
  87. where marina_slip.slip_id = service_request.slip_id
  88. and category_num =2;
  89. /*
  90. 15.) Repeat exercise 14, but this time be sure each slip is included regardless fo whether the boat in the slip currently has any service request for category 2. (12 rows)
  91. */
  92. select marina_slip.slip_id , boat_name ,owner_num ,service_id ,est_hours ,spent_hours
  93. from service_request left join marina_slip
  94. on marina_slip.slip_id = service_request.slip_id
  95. and category_num =2;
Advertisement
Add Comment
Please, Sign In to add comment