Computer Science
Consider the following MOVIE table and write the SQL queries based on it.
MovieID | MovieName | Category | ReleaseDate | ProductionCost | BusinessCost |
---|---|---|---|---|---|
001 | Hindi_Movie | Musical | 2018-04-23 | 124500 | 130000 |
002 | Tamil_Movie | Action | 2016-05-17 | 112000 | 118000 |
003 | English_Movie | Horror | 2017-08-06 | 245000 | 360000 |
004 | Bengali_Movie | Adventure | 2017-01-04 | 72000 | 100000 |
005 | Telugu_Movie | Action | - | 100000 | - |
006 | Punjabi_Movie | Comedy | - | 30500 | - |
(a) Display all the information from the Movie table.
(b) List business done by the movies showing only MovieID, MovieName and TotalEarning. TotalEarning 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.
SQL Queries
4 Likes
Answer
(a)
SELECT * FROM Movie;
Output
+---------+---------------+-----------+-------------+----------------+--------------+
| MOVIEID | MOVIENAME | CATEGORY | RELEASEDATE | PRODUCTIONCOST | BUSINESSCOST |
+---------+---------------+-----------+-------------+----------------+--------------+
| 1 | Hindi_Movie | Musical | 2018-04-23 | 124500 | 130000 |
| 2 | Tamil_Movie | Action | 2016-05-17 | 112000 | 118000 |
| 3 | English_Movie | Horror | 2017-08-06 | 245000 | 360000 |
| 4 | Bengali_Movie | Adventure | 2017-01-04 | 72000 | 100000 |
| 5 | Telugu_Movie | Action | NULL | 100000 | NULL |
| 6 | Punjabi_Movie | Comedy | NULL | 30500 | NULL |
+---------+---------------+-----------+-------------+----------------+--------------+
(b)
SELECT MovieID, MovieName, (ProductionCost + BusinessCost) AS Total_Earning
FROM Movie
WHERE ReleaseDate IS NOT NULL;
Output
+---------+---------------+---------------+
| MovieID | MovieName | Total_Earning |
+---------+---------------+---------------+
| 1 | Hindi_Movie | 254500 |
| 2 | Tamil_Movie | 230000 |
| 3 | English_Movie | 605000 |
| 4 | Bengali_Movie | 172000 |
+---------+---------------+---------------+
(c)
SELECT DISTINCT Category FROM MOVIE;
Output
+-----------+
| Category |
+-----------+
| Musical |
| Action |
| Horror |
| Adventure |
| Comedy |
+-----------+
(d)
SELECT MovieID, MovieName, BusinessCost - ProductionCost AS NetProfit
FROM Movie
WHERE ReleaseDate IS NOT NULL;
Output
+---------+---------------+-----------+
| MovieID | MovieName | NetProfit |
+---------+---------------+-----------+
| 1 | Hindi_Movie | 5500 |
| 2 | Tamil_Movie | 6000 |
| 3 | English_Movie | 115000 |
| 4 | Bengali_Movie | 28000 |
+---------+---------------+-----------+
(e)
SELECT MovieID, MovieName, ProductionCost AS Cost
FROM MOVIE
WHERE ProductionCost > 10000 AND ProductionCost < 100000;
Output
+---------+---------------+-------+
| MovieID | MovieName | Cost |
+---------+---------------+-------+
| 4 | Bengali_Movie | 72000 |
| 6 | Punjabi_Movie | 30500 |
+---------+---------------+-------+
(f)
SELECT * FROM MOVIE
WHERE Category = 'Comedy' OR Category = 'Action';
Output
+---------+---------------+----------+-------------+----------------+--------------+
| MOVIEID | MOVIENAME | CATEGORY | RELEASEDATE | PRODUCTIONCOST | BUSINESSCOST |
+---------+---------------+----------+-------------+----------------+--------------+
| 2 | Tamil_Movie | Action | 2016-05-17 | 112000 | 118000 |
| 5 | Telugu_Movie | Action | NULL | 100000 | NULL |
| 6 | Punjabi_Movie | Comedy | NULL | 30500 | NULL |
+---------+---------------+----------+-------------+----------------+--------------+
(g)
SELECT * FROM MOVIE
WHERE ReleaseDate IS NULL;
Output
+---------+---------------+----------+-------------+----------------+--------------+
| MOVIEID | MOVIENAME | CATEGORY | RELEASEDATE | PRODUCTIONCOST | BUSINESSCOST |
+---------+---------------+----------+-------------+----------------+--------------+
| 5 | Telugu_Movie | Action | NULL | 100000 | NULL |
| 6 | Punjabi_Movie | Comedy | NULL | 30500 | NULL |
+---------+---------------+----------+-------------+----------------+--------------+
Answered By
2 Likes
Related Questions
Write the name of the functions to perform the following operations:
- To display the day like 'Monday', 'Tuesday', from the date when India got independence.
- To display the specified number of characters from a particular position of the given string.
- To display the name of the month in which you were born.
- To display your name in capital letters.
Write the output produced by the following SQL statements:
(a)
SELECT POW(2, 3);
(b)
SELECT ROUND(342.9234, -1);
(c)
SELECT LENGTH("Informatics Practices");
(d)
SELECT YEAR("1979/11/26"), MONTH("1979/11/26"), DAY("1979/11/26"), MONTHNAME("1979/11/26");
(e)
SELECT LEFT("INDIA", 3), RIGHT("ComputerScience", 4), MID("Informatics", 3, 4), SUBSTR("Practices", 3);
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:
- It should have a column TeamID for storing an integer value between 1 to 9, which refers to unique identification of a team.
- 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 4: (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 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 TDATA. Also change the attributes TeamID and TeamName to TID and T_NAME respectively.