0% found this document useful (0 votes)
14 views3 pages

Lab Internal 2

The document contains a series of SQL queries and procedures related to sailors, boats, reservations, students, classes, and teachers. It includes tasks such as retrieving sailor information based on boat reservations, calculating average ages and GPAs, and creating procedures for data retrieval. The document also provides specific instances of data for the queries to be executed against.

Uploaded by

22wh1a0578
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views3 pages

Lab Internal 2

The document contains a series of SQL queries and procedures related to sailors, boats, reservations, students, classes, and teachers. It includes tasks such as retrieving sailor information based on boat reservations, calculating average ages and GPAs, and creating procedures for data retrieval. The document also provides specific instances of data for the queries to be executed against.

Uploaded by

22wh1a0578
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

1. Perform the following Queries on the below table data.

a. Find all information of sailors who have reserved boat number 101.
b. Find the names of sailors who have reserved a red boat, and list in the order of age.
c. Find the names of sailors who have reserved at least one boat.
d. Find the ids of sailors who have reserved a red boat or a green boat.
e. A trigger that prevents sailors with rating less than 3 from reserving a boat

Sailors(sid: integer, sname: string, rating: integer, age: real);


Boats(bid: integer, bname: string, color: string);
Reserves(sid: integer, bid: integer, day: date).

Instances of Sailors, Boats and Reserves


Sailor
(22, Dustin, 7, 45); (29, Brutus, 1, 33) (31, Lubber, 8, 55.5); (32, Andy, 8, 25.5); (58, Rusty,
10, 35); (64, Horatio, 7, 35); (71, Zorba, 10 ,16); (74, Horatio, 9, 40) (85, Art, 3, 25.5); (95,
Bob, 3, 63.5);
Boat
(101,Interlake,blue); (102,Interlake,red); (103,Clipper,green); (104,Marine,red)
Reservers
(22, 101, 1998-10-10); (22, 102, 1998-10-10); (22, 103, 1998-10-8); (22, 104, 1998-10-7);
(31, 102, 1998-11-10); (31, 103, 1998-11-6); (31, 104, 1998-11-12), (64, 101, 1998-9-5); (64,
102, 1998-9-8); (74, 103, 1998-9-8)

2. Perform the following Queries on the below table data.


a. Write a procedure to retrieve sailors information based on sailors id.
b. A view that shows names and ratings of all sailors sorted by rating in descending
order
c. Find the name and the age of the youngest sailor
d. Count the number of different sailor names
e. Find the average age of sailors for each rating level

Sailors(sid: integer, sname: string, rating: integer, age: real);


Boats(bid: integer, bname: string, color: string);
Reserves(sid: integer, bid: integer, day: date).

Instances of Sailors, Boats and Reserves


Sailor
(22, Dustin, 7, 45); (29, Brutus, 1, 33) (31, Lubber, 8, 55.5); (32, Andy, 8, 25.5); (58, Rusty,
10, 35); (64, Horatio, 7, 35); (71, Zorba, 10 ,16); (74, Horatio, 9, 40) (85, Art, 3, 25.5); (95,
Bob, 3, 63.5);
Boat
(101,Interlake,blue); (102,Interlake,red); (103,Clipper,green); (104,Marine,red)
Reservers
(22, 101, 1998-10-10); (22, 102, 1998-10-10); (22, 103, 1998-10-8); (22, 104, 1998-10-7);
(31, 102, 1998-11-10); (31, 103, 1998-11-6); (31, 104, 1998-11-12), (64, 101, 1998-9-5); (64,
102, 1998-9-8); (74, 103, 1998-9-8)
3. Perform the following Queries on the below table data.
a. Find the average age of sailors for each rating level that has at least two sailors.
b. Find the ages of sailors whose name begins and ends with B and has at least three
characters.
c. Find the sids of all sailors who have reserved red boats but not green boats.
d. Find all sids of sailors who have a rating of 10 or have reserved boat 104.
e. Create a procedure to calculate the max age of all the sailors and return it.

Sailors(sid: integer, sname: string, rating: integer, age: real);


Boats(bid: integer, bname: string, color: string);
Reserves(sid: integer, bid: integer, day: date).

Instances of Sailors, Boats and Reserves


Sailor
(22, Dustin, 7, 45); (29, Brutus, 1, 33) (31, Lubber, 8, 55.5); (32, Andy, 8, 25.5); (58, Rusty,
10, 35); (64, Horatio, 7, 35); (71, Zorba, 10 ,16); (74, Horatio, 9, 40) (85, Art, 3, 25.5); (95,
Bob, 3, 63.5);
Boat
(101,Interlake,blue); (102,Interlake,red); (103,Clipper,green); (104,Marine,red)
Reservers
(22, 101, 1998-10-10); (22, 102, 1998-10-10); (22, 103, 1998-10-8); (22, 104, 1998-10-7);
(31, 102, 1998-11-10); (31, 103, 1998-11-6); (31, 104, 1998-11-12), (64, 101, 1998-9-5); (64,
102, 1998-9-8); (74, 103, 1998-9-8)

4. Perform the following Queries on the below table data.


a. Find the colors of boats reserved by Lubber.
b. Find all sailors with a rating above 7.
c. Find sailors whose rating is better than some sailor called Horatio.
d. Find the name and age of the oldest sailor.
e. Write a procedure to retrieve reservation information based on sailors id.
Sailors(sid: integer, sname: string, rating: integer, age: real);
Boats(bid: integer, bname: string, color: string);
Reserves(sid: integer, bid: integer, day: date).

Instances of Sailors, Boats and Reserves


Sailor
(22, Dustin, 7, 45); (29, Brutus, 1, 33) (31, Lubber, 8, 55.5); (32, Andy, 8, 25.5); (58, Rusty,
10, 35); (64, Horatio, 7, 35); (71, Zorba, 10 ,16); (74, Horatio, 9, 40) (85, Art, 3, 25.5); (95,
Bob, 3, 63.5);
Boat
(101,Interlake,blue); (102,Interlake,red); (103,Clipper,green); (104,Marine,red)
Reservers
(22, 101, 1998-10-10); (22, 102, 1998-10-10); (22, 103, 1998-10-8); (22, 104, 1998-10-7);
(31, 102, 1998-11-10); (31, 103, 1998-11-6); (31, 104, 1998-11-12), (64, 101, 1998-9-5); (64,
102, 1998-9-8); (74, 103, 1998-9-8)
5. Perform the following Queries on the below table data.
a. find all students that have above-average GPAs
b. Find the highest GPAs for each class.
c. Find the subject name, no of students in the class of teacher id 4
d. Find name of students whose name starts with ‘S’.
e. Write a procedure to display no of students in a class for a given class_id.
Students Classes
id name class_id GPA
1 Jack Black 3 3.45 id grade teacher_id no_of_students
2 Daniel White 1 3.15 1 10 3 21
3 Kathrine Star 1 3.85 2 11 4 25
4 Helen Bright 2 3.10 3 12 1 28
5 Steve May 2 2.40
6 Strom 3 4.05

Teachers
id name subject class_id monthly_salary
1 Elisabeth Grey History 3 2,500
2 Robert Sun Literature [NULL] 2,000
3 John Churchill English 1 2,350
4 Sara Parker Math 2 3,000

6. Perform the following Queries on the below table data.


a. Find out the name of name of the student, class id and subject for teachers_id 1.
b. Find the average GPAs.
c. Find the name of the students and GPA of students whose GPA in between 3 and 4
d. Find out the name of the student and teachers name who has highest GPA.
e. Write a procedure to display student name and GPA of a given student id.
Students Classes
id name class_id GPA
1 Jack Black 3 3.45 id grade teacher_id no_of_students
2 Daniel White 1 3.15 1 10 3 21
3 Kathrine Star 1 3.85 2 11 4 25
4 Helen Bright 2 3.10 3 12 1 28
5 Steve May 2 2.40
6 Strom 3 4.05

Teachers
id name subject class_id monthly_salary
1 Elisabeth Grey History 3 2,500
2 Robert Sun Literature [NULL] 2,000
3 John Churchill English 1 2,350
4 Sara Parker Math 2 3,000

You might also like