Practical 16-18
Practical 16-18
Practical 16-18
+---------+---------------+-----------+-------------+----------------+--------------+
+---------+---------------+-----------+-------------+----------------+--------------+
+---------+---------------+-----------+-------------+----------------+--------------+
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
mysql> SELECT MOVIEID,MOVIENAME,PRODUCTIONCOST+IFNULL(BUSINESSCOST,0) AS
TOTAL_EARNING FROM MOVIE;
+---------+---------------+---------------+
| MOVIEID | MOVIENAME | TOTAL_EARNING |
+---------+---------------+---------------+
| 001 | HINDI_MOVIE | 254500 |
| 002 | TAMIL_MOVIE | 230000 |
| 003 | ENGLISH_MOVIE | 605000 |
| 004 | BENGALI_MOVIE | 172000 |
| 005 | TELUGU_MOVIE | 100000 |
| 006 | PUNJABI_MOVIE | 30500 |
+---------+---------------+---------------+
6 rows in set (0.00 sec)
(c )List the different categories of movies.
mysql> SELECT DISTINCT CATEGORY FROM MOVIE;
+-----------+
| CATEGORY |
+-----------+
| MUSICAL |
| ACTION |
| HORROR |
| ADVENTURE |
| COMEDY |
+-----------+
5 rows in set (0.04 sec)
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.
mysql> SELECT MOVIEID,MOVIENAME,BUSINESSCOST-PRODUCTIONCOST AS NET_PROFIT FROM MOVIE;
+---------+---------------+------------+
+---------+---------------+------------+
+---------+---------------+------------+
e) List MovieID, MovieName and Cost for all movies with ProductionCost greater than 10,000 and less than
1,00,000
mysql> SELECT MOVIEID,MOVIENAME,PRODUCTIONCOST FROM MOVIE WHERE PRODUCTIONCOST>10000
AND PRODUCTIONCOST<100000;
+---------+---------------+----------------+
+---------+---------------+----------------+
f) List details of all movies which fall in the category of comedy or action.
mysql> SELECT * FROM MOVIE WHERE CATEGORY IN('COMEDY','ACTION');
+---------+---------------+----------+-------------+----------------+--------------+
+---------+---------------+----------+-------------+----------------+--------------+
+---------+---------------+----------+-------------+----------------+--------------+
g) List details of all movies which have not been released yet
mysql> SELECT * FROM MOVIE WHERE RELEASEDATE IS NULL;
+---------+---------------+----------+-------------+----------------+--------------+
+---------+---------------+----------+-------------+----------------+--------------+
+---------+---------------+----------+-------------+----------------+--------------+
+-------+----------------+--------+--------------+----------+
+-------+----------------+--------+--------------+----------+
+-------+----------------+--------+--------------+----------+
f) Increase the price by 12 per cent for all the products manufactured by Dove.
mysql> UPDATE PRODUCT SET UPRICE=UPRICE+0.12*UPRICE WHERE MANUFACTURER='DOVE';
+-------+----------------+--------+--------------+----------+
+-------+----------------+--------+--------------+----------+
+-------+----------------+--------+--------------+----------+
+--------------+---------------------+
| MANUFACTURER | COUNT(MANUFACTURER) |
+--------------+---------------------+
| SURF | 1 |
| COLGATE | 1 |
| LUX | 1 |
| PEPSODENT | 1 |
| DOVE | 2 |
+--------------+---------------------+
a) Create the table Product with appropriate data types and constraints.
mysql> USE PRACTICALS;
Database changed
mysql> CREATE TABLE PRODUCT
-> (
-> PCODE CHAR(3) PRIMARY KEY,
-> PNAME VARCHAR(20),
-> UPRICE INT(3),
-> MANUFACTURER VARCHAR(20));
Query OK, 0 rows affected, 1 warning (0.07 sec)
mysql> INSERT INTO PRODUCT VALUES
-> ('P01','WASHING POWDER',120,'SURF'),
-> ('P02','TOOTHPASTE',54,'COLGATE'),
-> ('P03','SOAP',25,'LUX'),
-> ('P04','TOOTHPASTE',65,'PEPSODENT'),
-> ('P05','SOAP',38,'DOVE'),
-> ('P06','SHAMPOO',245,'DOVE');
Query OK, 6 rows affected (0.00 sec)
Records: 6 Duplicates: 0 Warnings: 0
#SHOWING TABLE DETAILS
mysql> SELECT * FROM PRODUCT;
+-------+----------------+--------+--------------+
| PCODE | PNAME | UPRICE | MANUFACTURER |
+-------+----------------+--------+--------------+
| P01 | WASHING POWDER | 120 | SURF |
| P02 | TOOTHPASTE | 54 | COLGATE |
| P03 | SOAP | 25 | LUX |
| P04 | TOOTHPASTE | 65 | PEPSODENT |
| P05 | SOAP | 38 | DOVE |
| P06 | SHAMPOO | 245 | DOVE |
+-------+----------------+--------+--------------+
6 rows in set (0.00 sec)
C) List the Product Code, Product name and price in descending order of their
product name. If PName is the same, then display the data in ascending order of
price.
mysql> SELECT PCODE,PNAME,UPRICE FROM PRODUCT ORDER BY PNAME DESC,UPRICE ASC;
+-------+----------------+--------+
| PCODE | PNAME | UPRICE |
+-------+----------------+--------+
| P01 | WASHING POWDER | 120 |
| P02 | TOOTHPASTE | 54 |
| P04 | TOOTHPASTE | 65 |
| P03 | SOAP | 25 |
| P05 | SOAP | 38 |
| P06 | SHAMPOO | 245 |
+-------+----------------+--------+
6 rows in set (0.00 sec)