SQL- Practice Problem2
SQL- Practice Problem2
Part (1)
Question 1:
Consider the following relational database for the Super Baseball League. It keeps track of teams in the
league, coaches and players on the teams, work experience of the coaches, bats belonging to each
team, and which players have played on which teams.
• The database keeps track of the history of all the teams that each player has played on and all
the players who have played on each team.
• The database only keeps track of the current team that a coach works for.
• Team number, team name, and player number are each unique attributes across the league.
• Coach name is unique only within a team (and we assume that a team cannot have two coaches
of the same name).
• Serial number (for bats) is unique only within a team.
• In the Affiliation table, the Years attribute indicates the number of years that a player played on
a team; the batting average is for the years that a player played on a team.
1. Find the names and cities of all of the teams with team numbers greater than 15.
2. List all of the coaches who have between 5 and 10 years of experience as college coaches (see
YEARSEXPERIENCE and EXPERIENCETYPE).
3. Find the total number of years of experience of Coach Waqar on team number 23.
4. Find the number of different types of experience that Coach Waqar on team number 23 has.
5. Find the total number of years of experience of each coach on team number 23.
6. How many different manufacturers make bats for the league’s teams?
7. Assume that team names are unique. Find the names of the players who have played for the
Dodgers for at least five years (see YEARS in the AFFILIATION Table.)
9. Find the players who have been affiliated with more than two teams.
10. Find the players who are not affiliated with any team.
11. For each player, find the number of teams they have been affiliated with in their career.
Question 2:
Use schema of Q1 and write only nested SQL queries for the following questions.
1. Display the name of the teams such that their coach is Waqar.
2. Display the names of the players who are under 18.
3. Find the name of players such that their age is more than the average age. Sort the results in descending
order of age.
4. Assume that team names are unique. Find the total number of years of work experience of each
coach on the Dodgers, but include in the result only those coaches who have more than eight
years of experience.
5. Find the manufacturers who have made bats for all the teams in New York.
Question 3: