Using the sports database containing two relations (TEAM, MATCH_DETAILS), answer the following relational algebra queries.


(a) Retrieve the MatchID of all those matches where both the teams have scored > 70.
Ans:  
SELECT MatchID FROM MATCH_DETAILS
WHERE FirstTeamScore >70 AND SecondTeamScore >70;
(b) Retrieve the MatchID of all those matches where FirstTeam has scored < 70 but SecondTeam has scored > 70.
Ans:
SELECT MatchID FROM MATCH_DETAILS
WHERE FirstTeamScore <70 AND SecondTeamScore >70;

(c) Find out the MatchID and date of matches played by Team 1 and won by it.
Ans:
SELECT MatchID, MatchDate FROM MATCH_DETAILS
WHERE FirstTeamID = 1 AND FirstTeamScore > SecondTeamScore;

(d) Find out the MatchID of matches played by Team 2 and not won by it.
Ans:
SELECT MatchID FROM MATCH_DETAILS
WHERE FirstTeamID = 2 AND FirstTeamScore > SecondTeamScore;

(e) In the TEAM relation, change the name of the relation to T_DATA. Also change the attributes TeamID and TeamName to T_ID and T_NAME respectively.
Ans:
RENAME TABLE TEAM TO T_DATA;
ALTER TABLE TEAMS
RENAME TeamID T_ID INT,
RENAME TeamData T_DATA VARCHAR(20);

Leave a Comment

Your email address will not be published. Required fields are marked *

error: Content is protected !!