Print DB
Print DB
Project Assignment
Submitted by:
Supervised by:
Course:
Database Systems
ER Diagram:
3
USE [PSL ]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
) ON [PRIMARY]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
[MatchID] ASC
) ON [PRIMARY]
GO
5
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
[PlayerID] ASC
) ON [PRIMARY]
GO
6
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
[PlayerID] ASC
) ON [PRIMARY]
GO
7
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
[TeamID] ASC
) ON [PRIMARY]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
[TeamID] ASC
) ON [PRIMARY]
GO
SET ANSI_NULLS ON
9
GO
SET QUOTED_IDENTIFIER ON
GO
[TicketID] ASC
) ON [PRIMARY]
GO
SET ANSI_NULLS ON
GO
10
SET QUOTED_IDENTIFIER ON
GO
[UserID] ASC
) ON [PRIMARY]
GO
GO
GO
GO
GO
GO
GO
GO
GO
GO
13
Problem Statements:
1. Determine the number of matches played by each player and the number of matches
drawn by each player.
2. Identify the players who have scored the most runs in a particular year.
3. Calculate the total number of runs scored by each player and the number of wickets
taken by each player.
4. Determine the total number of matches played by each player and the number of
matches won by each player.
5. Identify the players who have taken the most wickets in a particular season.
6. Calculate the total number of wickets taken by each player and the number of runs
conceded by each player.
7. Identify the players who have scored the most runs in a particular match.
8. Determine the total number of matches played by each player and the number of
matches won by each player.
9. Identify the players who have taken the most wickets in a particular season.
10. Calculate the total number of wickets taken by each player and the number of runs
conceded by each player.
11. Identify the players who have scored the most runs in a particular year.
12. Determine the number of matches played by each player and the number of matches
lost by each player.
13. Identify the players who have scored the most centuries in a particular season.
14. Calculate the total number of runs scored by each team and the number of wickets
taken by each team.
15. Determine the total number of matches played by each team and the number of
matches won by each team.
16. Identify the players who have taken the most wickets in a particular match.
17. Calculate the total number of wickets taken by each team and the number of runs
conceded by each team.
18. Identify the players who have scored the most runs in a particular match.
19. Determine the total number of matches played by each player and the number of
matches won by each player.
20. Iden
14
SQL Commands:
-- 1. Determine the number of matches played by each player and the number of matches
drawn by each player.
SELECT Players.PlayerID, COUNT(*) AS TotalMatchesPlayed,
SUM(CASE WHEN Matches.Winner IS NULL THEN 1 ELSE 0 END) AS
MatchesDrawn
FROM Players
LEFT JOIN Matches ON Players.TeamID = Matches.TeamID
GROUP BY Players.PlayerID;
-- 2. Identify the players who have scored the most runs in a particular year.
SELECT PlayerID, SUM(RunsScored) AS TotalRuns
FROM PlayerStatistics
WHERE YEAR(Date) = <year>
GROUP BY PlayerID
ORDER BY TotalRuns DESC
LIMIT 1;
-- 3. Calculate the total number of runs scored by each player and the number of wickets
taken by each player.
SELECT PlayerID, SUM(RunsScored) AS TotalRuns, SUM(WicketsTaken) AS TotalWickets
FROM PlayerStatistics
GROUP BY PlayerID;
-- 4. Determine the total number of matches played by each player and the number of
matches won by each player.
SELECT Players.PlayerID, COUNT(*) AS TotalMatchesPlayed,
SUM(CASE WHEN Matches.Winner = Players.TeamID THEN 1 ELSE 0 END) AS
MatchesWon
FROM Players
LEFT JOIN Matches ON Players.TeamID = Matches.TeamID
15
GROUP BY Players.PlayerID;
-- 5. Identify the players who have taken the most wickets in a particular season.
SELECT PlayerID, SUM(WicketsTaken) AS TotalWickets
FROM PlayerStatistics
WHERE Season = '<season>'
GROUP BY PlayerID
ORDER BY TotalWickets DESC
LIMIT 1;
-- 6. Calculate the total number of wickets taken by each player and the number of runs
conceded by each player.
SELECT PlayerID, SUM(WicketsTaken) AS TotalWickets, SUM(RunsConceded) AS
TotalRunsConceded
FROM PlayerStatistics
GROUP BY PlayerID;
-- 7. Identify the players who have scored the most runs in a particular match.
SELECT PlayerID, SUM(RunsScored) AS TotalRuns
FROM PlayerStatistics
WHERE MatchID = <match_id>
GROUP BY PlayerID
ORDER BY TotalRuns DESC
LIMIT 1;
-- 8. Determine the total number of matches played by each player and the number of
matches won by each player.
SELECT Players.PlayerID, COUNT(*) AS TotalMatchesPlayed,
SUM(CASE WHEN Matches.Winner = Players.TeamID THEN 1 ELSE 0 END) AS
MatchesWon
FROM Players
LEFT JOIN Matches ON Players.TeamID = Matches.TeamID
16
GROUP BY Players.PlayerID;
-- 9. Identify the players who have taken the most wickets in a particular season.
SELECT PlayerID, SUM(WicketsTaken) AS TotalWickets
FROM PlayerStatistics
WHERE Season = '<season>'
GROUP BY PlayerID
ORDER BY TotalWickets DESC
LIMIT 1;
-- 10. Calculate the total number of wickets taken by each player and the number of runs
conceded by each player.
SELECT PlayerID, SUM(WicketsTaken) AS TotalWickets, SUM(RunsConceded) AS
TotalRunsConceded
FROM PlayerStatistics
GROUP BY PlayerID;
-- 11. Identify the players who have scored the most runs in a particular year.
SELECT PlayerID, SUM(RunsScored) AS TotalRuns
FROM PlayerStatistics
WHERE YEAR(Date) = <year>
GROUP BY PlayerID
ORDER BY TotalRuns DESC
LIMIT 1;
-- 12. Determine the number of matches played by each player and the number of matches
lost by each player.
SELECT Players.PlayerID, COUNT(*) AS TotalMatchesPlayed,
SUM(CASE WHEN Matches.Winner != Players.TeamID THEN 1 ELSE 0 END) AS
MatchesLost
FROM Players
LEFT JOIN Matches ON Players.TeamID = Matches.TeamID
17
GROUP BY Players.PlayerID;
-- 13. Identify the players who have scored the most centuries in a particular season.
SELECT PlayerID, COUNT(*) AS Centuries
FROM PlayerStatistics
WHERE RunsScored >= 100 AND Season = '<season>'
GROUP BY PlayerID
ORDER BY Centuries DESC
LIMIT 1;
-- 14. Calculate the total number of runs scored by each team and the number of wickets
taken by each team.
SELECT TeamID, SUM(RunsScored) AS TotalRuns, SUM(WicketsTaken) AS TotalWickets
FROM PlayerStatistics
GROUP BY TeamID;
-- 15. Determine the total number of matches played by each team and the number of matches
won by each team.
SELECT Matches.TeamID, COUNT(*) AS TotalMatchesPlayed,
SUM(CASE WHEN Matches.Winner = Matches.TeamID THEN 1 ELSE 0 END) AS
MatchesWon
FROM Matches
GROUP BY Matches.TeamID;
-- 16. Identify the players who have taken the most wickets in a particular match.
SELECT PlayerID, WicketsTaken
FROM PlayerStatistics
WHERE MatchID = <match_id>
ORDER BY WicketsTaken DESC
LIMIT 1;
18
-- 17. Calculate the total number of wickets taken by each team and the number of runs
conceded by each team.
SELECT Matches.TeamID, SUM(WicketsTaken) AS TotalWickets, SUM(RunsConceded)
AS TotalRunsConceded
FROM Matches
INNER JOIN PlayerStatistics ON Matches.MatchID = PlayerStatistics.MatchID
GROUP BY Matches.TeamID;
-- 18. Identify the players who have scored the most runs in a particular match.
SELECT PlayerID, SUM(RunsScored) AS TotalRuns
FROM PlayerStatistics
WHERE MatchID = <match_id>
GROUP BY PlayerID
ORDER BY TotalRuns DESC
LIMIT 1;
-- 19. Determine the total number of matches played by each player and the number of
matches won by each player.
SELECT Players.PlayerID, COUNT(*) AS TotalMatchesPlayed,
SUM(CASE WHEN Matches.Winner = Players.TeamID THEN 1 ELSE 0 END) AS
MatchesWon
FROM Players
LEFT JOIN Matches ON Players.TeamID = Matches.TeamID
GROUP BY Players.PlayerID;
-- 20. Identify the players who have taken the most wickets in a particular season.
SELECT PlayerID, SUM(WicketsTaken) AS TotalWickets
FROM PlayerStatistics
WHERE Season = '<season>'
GROUP BY PlayerID
ORDER BY TotalWickets DESC
LIMIT 1;