Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- 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)
- */
- select marina_num, slip_num, boat_name, owner.owner_num, first_name,last_name
- from marina_slip,owner
- where marina_slip.owner_num=owner.owner_num;
- /*
- 2.) For every completed or open service request for routine engine maintenance, list the slip ID, description, and status. (1 row)
- */
- select slip_id,description, status
- from service_request, service_category
- where service_request.category_num= service_category.category_num and category_description= 'routine engine maintenance';
- /*
- 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)
- */
- /*
- 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)
- */
- select first_name, last_name from owner where owner_num in (select owner_num from marina_slip where length = '40');
- /*
- 5.)Repeat number 4, but this time use the EXISTS operator in your formulation. (5 rows)
- */
- select last_name, first_name
- from owner
- where exists
- (select * from marina_slip where marina_slip.owner_num= owner.owner_num and length ='40');
- /*
- 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)
- */
- select x.boat_name, y.boat_name, x.boat_type
- from marina_slip x, marina_slip y
- where x.boat_type=y.boat_type and x.boat_name < y.boat_name;
- /*
- 7.) List the boat name, owner number, owner last name, and owner first name for each boat in marina 1. (5 rows)
- */
- select boat_name, owner.owner_num, last_name, first_name
- from marina_slip,owner
- where marina_slip.owner_num=owner.owner_num and marina_num =1;
- /*
- 8.)Repeat number 7, but this time only lists boats in 30-foot slips. (2 rows)
- */
- select boat_name, owner.owner_num,last_name, first_name
- from marina_slip, owner
- where marina_slip.owner_num= owner.owner_num and marina_num = 1 and length =30;
- /*
- 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)
- */
- select marina_num, slip_num,boat_name
- from marina_slip,owner
- where marina_slip.owner_num= owner.owner_num and city= 'Glander Bay'
- Union
- select marina_num, slip_num, boat_name
- from marina_slip
- where boat_type='Sprite 4000';
- /*
- 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)
- */
- select marina_num,slip_num,boat_name,owner.owner_num
- from marina_slip,owner
- where marina_slip.owner_num = owner.owner_num
- and city= 'Glander Bay';
- /*
- 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)
- */
- /*
- 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)
- */
- select service_id, slip_id
- from service_request
- where est_hours > any (select est_hours from service_request where category_num =3);
- /*
- 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)
- */
- select service_id, slip_id
- from service_request
- where est_hours > all (select est_hours from service_request where category_num =3);
- /*
- 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)
- */
- select marina_slip.slip_id, boat_name,owner_num,service_id,est_hours,spent_hours
- from service_request, marina_slip
- where marina_slip.slip_id = service_request.slip_id
- and category_num =2;
- /*
- 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)
- */
- select marina_slip.slip_id , boat_name ,owner_num ,service_id ,est_hours ,spent_hours
- from service_request left join marina_slip
- on marina_slip.slip_id = service_request.slip_id
- and category_num =2;
Advertisement
Add Comment
Please, Sign In to add comment