Question
5. There are 4 relations in the schema, which are described below along with their integrity constraints. Columns in the primary key are underlined. Player(
5. There are 4 relations in the schema, which are described below along with their integrity constraints. Columns in the primary key are underlined.
Player(playerID: integer, name : varchar(50), position : varchar(10), height : integer, weight : integer, team: varchar(30))
Each Player is assigned a unique playerID. The position of a player can either be Guard, Center or Forward. The height of a player is in inches while the weight is in pounds. Each player plays for only one team. The team field is a foreign key to Team.
Each Team has a unique name associated with it. There can be multiple teams from the same city.
Game (gameID: integer, homeTeam: varchar(30), awayTeam : varchar(30), homeScore : integer, awayScore : integer)
Each Game has a unique gameID. The fields homeTeam and awayTeam are foreign keys to Team. Two teams may play each other multiple times each season. There is an integrity check to ensure homeTeam and awayTeam are different.
GameStats records the performance statistics of a player within a game. A player may not play in every game, in which case it will not have its statistics recorded for that game. gameID is a foreign key to Game. playerID is a foreign key to Player. Assume that two assertions are in place. The first is to ensure that the player involved belongs to either the involving home or away teams, and the second is to ensure that the total score obtained by a team (in Game) is consistent with the total sum (in GameStats) of individual players in the team playing in the game[2].
Write out SQL statements for the following 10 queries.
Note: You are asked to order the result of each query by some attribute(s) using keyword ORDER BY - you need to find out its usage by yourself.
?
1) Find the names of the shortest player(s) playing the "Guard" position for each team. (ORDER BY Players.name)
select list: Player.name
ordering: Player.name ascending
2) List the names of all players and the average number of points and rebounds for all games that they played in, ignoring players who did not play in any games. (ORDER BY Player.name)
select list: Player.name, average_points, average_rebounds
ordering: Player.name descending
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started