0% found this document useful (0 votes)
2 views

SQL- Practice Problem2

The document outlines a practice problem for a Database Systems course, focusing on a relational database for the Super Baseball League. It includes tasks for creating SQL DDL statements, writing SQL queries for various data retrieval tasks, and formulating nested SQL queries based on a different schema. The questions cover aspects such as team and player information, coach experience, and product details.

Uploaded by

tfaizanvr
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)
2 views

SQL- Practice Problem2

The document outlines a practice problem for a Database Systems course, focusing on a relational database for the Super Baseball League. It includes tasks for creating SQL DDL statements, writing SQL queries for various data retrieval tasks, and formulating nested SQL queries based on a different schema. The questions cover aspects such as team and player information, coach experience, and product details.

Uploaded by

tfaizanvr
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

National University of Computer and Emerging Sciences, Lahore Campus

Course: Database Systems


Program: BS(Computer Science)
Instructor: Muhammad Ishaq Raza

Practice Problem: SQL (2)

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.

Note the following facts about this environment:

• 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.

Team (TeamNum, TeamName, City, Manager)


Coach (TeamNum, CoachName, Address )
WorkExperience (TeamNum, CoachName, ExperienceType, YearsExperience)
Bats( TeamNum, SerialNum, Manufacturer)
Player (PlayerNum, PlayerName, Age)
Affiliation (PlayerNum, TeamNum, Years, BattingAvg)
a) Write appropriate SQL DDL statements for declaring the above relational schema. Specify the
appropriate keys and referential integrity constraints and actions. Also populate some data in tables.

b) Write down SQL queries for each statement.

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.)

8. Find the names of the league’s youngest players.

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.

12. For each team, list the average batting average.


Part (2)

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:

Product ( pid, name, price, category, maker-cid)


Purchase (buyer-ssn, seller-ssn, store, pid)
Company (cid, name, stock price, country)
Person (ssn, name, phone number, city)

Write only nested SQL queries for the following questions.

1. Display the name of products manufactured by ‘LG’


2. Find the name of products whose price is more than the average price range. Sort the results in descending
order of prices.
3. Display the name and company of all products made in Pakistan.
4. Display the name, phone of all buyers who buy products from ‘Ali’.
5. Create a query to display the name of products that have the same price as that of product id, pid=1.

You might also like