a) Display all the information from the Movie table.
b) List business done by the movies showing only MovieID, MovieName and Total_Earning. Total_ Earning to be calculated as the sum of ProductionCost and BusinessCost.
c) List the different categories of movies.
d) Find the net profit of each movie showing its MovieID, MovieName and NetProfit. Net Profit is to be calculated as the difference between Business Cost and Production Cost.
e) List MovieID, MovieName and Cost for all movies with ProductionCost greater than 10,000 and less than 1,00,000.
f) List details of all movies which fall in the category of comedy or action.
g) List details of all movies which have not been released yet.
Solution:
a) SELECT * FROM MOVIE;
b) SELECT MovieID, MovieName, ProductionCost + BusinessCost as “Total_Earning” FROM MOVIE;
c) SELECT DISTINCT Category FROM MOVIE;
OR
SELECT DISTINCT(Category) FROM MOVIE;
d) SELECT MovieID, MovieName, BusinessCost – ProductionCost as “Net Profict” FROM MOVIE;
e) SELECT MovieID, MovieName, ProductionCost FROM MOVIE WHERE ProductionCost > 10000 and ProductionCost < 100000;
f) SELECT * FROM MOVIE WHERE Category IN (‘Comedy’, ‘Action’);
g) SELECT * FROM MOVIE WHERE ReleaseDate IS NULL;
4. Suppose your school management has decided to conduct cricket matches between students of Class XI and Class XII. Students of each class are asked to join any one of the four teams – Team Titan, Team Rockers, Team Magnet and Team Hurricane. During summer vacations, various matches will be conducted between these teams. Help your sports teacher to do the following:
a) Create a database “Sports”.
b) Create a table “TEAM” with following considerations:
i) It should have a column TeamID for storing an integer value between 1 to 9, which refers to unique identification of a team.
ii) Each TeamID should have its associated name (TeamName), which should be a string of length not less than 10 characters.
c) Using table level constraint, make TeamID as the primary key.
d) Show the structure of the table TEAM using a SQL statement. e) As per the preferences of the students four teams were formed as given below. Insert these four rows in TEAM table: Row 1: (1, Team Titan)
Row 2: (2, Team Rockers)
Row 3: (3, Team Magnet)
Row 3: (4, Team Hurricane)
f) Show the contents of the table TEAM using a DML statement.
g) Now create another table MATCH_DETAILS and insert data as shown below. Choose appropriate data types and constraints for each attribute.
Table: MATCH_DETAILS
MatchID |
MatchDate |
FirstTeamID |
SecondTeamID |
FirstTeamScore |
SecondTeamScore |
M1 |
2018-07-17 |
1 |
2 |
90 |
86 |
M2 |
2018-07-18 |
3 |
4 |
45 |
48 |
M3 |
2018-07-19 |
1 |
3 |
78 |
56 |
M4 |
2018-07-19 |
2 |
4 |
56 |
67 |
M5 |
2018-07-18 |
1 |
4 |
32 |
87 |
M6 |
2018-07-17 |
2 |
3 |
67 |
51 |
Solution:
a) CREATE DATABASE Sports;
b) CREATE TABLE TEAM (TeamID int (3) Unique, TeamName varchar (30));
c) ALTER TABLE TEAM ADD Primary key (TeamID);
d) DESC TEAM;
e) INSERT INTO TEAM (TeamID, TeamName) VALUES (1, 'Team Titan'), (2, Team Rockers'), (3, Team Magnet'), (4, 'Team Hurricane');
f) SELECT "FROM TEAM;
g) CREATE TABLE MATCH DETAILS (MatchID varchar (5) Primary key, MatchDate DATE, First TeamID int (2), Second TeamID int(2), First TeamScore int (5), SecondTeamScore int (5));
INSERT INTO MATCH-DETAILS (MatchID, MatchDate, First TeamID, SecondTeamID, First TeamScore, Second'TeamScore) VALUES
('M1', 2018 - 17 - 17', 1, 2, 90, 86),
(M2', 2018 - 07 - 18', 3, 4, 45, 48),
(M3', 2018 - 07 - 19', 1, 3, 78, 56),
(M4', 2018 - 07 - 19', 2, 4, 56, 67),
(M5', 2018 - 07 - 20', 1, 4, 32, 87),
(M6', 2018 - 07 - 21', 2, 3, 67, 51);
5. Using the sports database containing two relations (TEAM, MATCH_DETAILS) and write the queries for the following:
a) Display the MatchID of all those matches where both the teams have scored more than 70.
b) Display the MatchID of all those matches where FirstTeam has scored less than 70 but SecondTeam has scored more than 70.
c) Display the MatchID and date of matches played by Team 1 and won by it.
d) Display the MatchID of matches played by Team 2 and not won by it.
e) Change the name of the relation TEAM to T_DATA. Also change the attributes TeamID and TeamName to T_ID and T_NAME respectively.
Solution:
a) SELECT MatchID FROM MATCH_DETAILS WHERE FirstTeamScore > 70 AND SecondTeamScore > 70;
b) SELECT MatchID FROM MATCH_DETAILS WHERE FirstTeamScore < 70 AND SecondTeamScore < 70;
c) SELECT MatchID, MatchDate FROM MATCH_DETAILS
WHERE (FirstTeamId = 1 AND FirstTeamScore > SecondTeamScore) OR (SecondTeamID = 1 AND SecondTeamScore > FirstTeamScore);
d) SELECT MatchID FROM MATCH_DETAILS WHERE SecondTeamScore < FirstTeamScore AND (FirstTeamID = 2 OR SecondTeamID = 2);
e) ALTER TABLE TEAM RENAME TO T_DATA;
ALTER TABLE T_DATA CHANGE TeamID T_ID INTEGER;
ALTER TABLE T_DATA CHANGE TeamName T_Name VARCHAR(30);