0% found this document useful (0 votes)
20 views

SQL Assignment Ms Word

The document describes SQL queries performed on a Movie database table with columns for movie details like title, type, rating, stars, quantity, and price. A number of queries are run to insert movie records, select, update, delete records matching certain criteria, and perform aggregate functions like count, sum, avg and group by.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views

SQL Assignment Ms Word

The document describes SQL queries performed on a Movie database table with columns for movie details like title, type, rating, stars, quantity, and price. A number of queries are run to insert movie records, select, update, delete records matching certain criteria, and perform aggregate functions like count, sum, avg and group by.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

ASSIGNMENT 1

Practical 1:

mysql> create table Movie(MNO int(5),TITLE varchar(30),TYPE varchar(10),RATING


varchar(5),STARS varchar(50),QTY int(5),PRICE float(10,2),ENTRY_DATE date);
Query OK, 0 rows affected, 3 warnings (1.78 sec)

Practical 2:

mysql> insert into Movie values(1,'Gone With The


Wind','Drama','G','Gable',4,39.50,'2001-01-21');
Query OK, 1 row affected (0.22 sec)

mysql> insert into Movie values(2,'Friday The


13','Horror','R','Jason',2,69.00,'2001-01-27');
Query OK, 1 row affected (0.13 sec)

mysql> insert into Movie values(3,'Top Gun','Drama','PG','Cruise',7,49.00,'2001-02-


13');
Query OK, 1 row affected (0.07 sec)

mysql> insert into Movie values(4,'Splash','Comedy','PG13',NULL,3,29.50,'2010-11-


21');
Query OK, 1 row affected (0.13 sec)

mysql> insert into Movie values(5,'Independence Day','Drama','R','Turner',3,19.00,


'2008-01-01');
Query OK, 1 row affected (0.11 sec)

Practical 3:

1. mysql> select * from movie;


+------+--------------------+--------+--------+--------+------+-------+------------+
| MNO | TITLE | TYPE | RATING | STARS | QTY | PRICE | ENTRY_DATE |
+------+--------------------+--------+--------+--------+------+-------+------------+
| 1 | Gone With The Wind | Drama | G | Gable | 4 | 39.50 | 2001-01-21 |
| 2 | Friday The 13 | Horror | R | Jason | 2 | 69.00 | 2001-01-27 |
| 3 | Top Gun | Drama | PG | Cruise | 7 | 49.00 | 2001-02-13 |
| 4 | Splash | Comedy | PG13 | NULL | 3 | 29.50 | 2010-11-21 |
| 5 | Independence Day | Drama | R | Turner | 3 | 19.00 | 2008-01-01 |
+------+--------------------+--------+--------+--------+------+-------+------------+
5 rows in set (0.00 sec)

2. mysql> delete from Movie where QTY<2;


Query OK, 0 rows affected (0.12 sec)

3. mysql> update Movie set QTY=QTY+3 where TYPE='Comedy';


Query OK, 1 row affected (0.14 sec)
Rows matched: 1 Changed: 1 Warnings: 0

4. mysql> select * from Movie where TITLE like 'C%' or TITLE like'T%';
+------+---------+-------+--------+--------+------+-------+------------+
| MNO | TITLE | TYPE | RATING | STARS | QTY | PRICE | ENTRY_DATE |
+------+---------+-------+--------+--------+------+-------+------------+
| 3 | Top Gun | Drama | PG | Cruise | 7 | 49.00 | 2001-02-13 |
+------+---------+-------+--------+--------+------+-------+------------+
1 row in set (0.04 sec)

5. mysql> delete from Movie where TITLE='Scientific';


Query OK, 0 rows affected (0.00 sec)

6. mysql> select * from Movie where PRICE>20 order by Price;


+------+--------------------+--------+--------+--------+------+-------+------------+
| MNO | TITLE | TYPE | RATING | STARS | QTY | PRICE | ENTRY_DATE |
+------+--------------------+--------+--------+--------+------+-------+------------+
| 4 | Splash | Comedy | PG13 | NULL | 6 | 29.50 | 2010-11-21 |
| 1 | Gone With The Wind | Drama | G | Gable | 4 | 39.50 | 2001-01-21 |
| 3 | Top Gun | Drama | PG | Cruise | 7 | 49.00 | 2001-02-13 |
| 2 | Friday The 13 | Horror | R | Jason | 2 | 69.00 | 2001-01-27 |
+------+--------------------+--------+--------+--------+------+-------+------------+
4 rows in set (0.07 sec)

7. mysql> select TITLE,RATING,STARS from Movie where TYPE='Comedy' order by RATING


desc;
+--------+--------+-------+
| TITLE | RATING | STARS |
+--------+--------+-------+
| Splash | PG13 | NULL |
+--------+--------+-------+
1 row in set (0.04 sec)

8. mysql> select sum(PRICE*QTY) from Movie;


+----------------+
| sum(PRICE*QTY) |
+----------------+
| 873.00 |
+----------------+
1 row in set (0.00 sec)

9. mysql> select count(*) from Movie where RATING!='G';


+----------+
| count(*) |
+----------+
| 4 |
+----------+
1 row in set (0.04 sec)

10. mysql> alter table Movie modify TITLE varchar(40);


Query OK, 0 rows affected (1.28 sec)
Records: 0 Duplicates: 0 Warnings: 0
11. mysql> select avg(PRICE) from Movie where Price<30;
+------------+
| avg(PRICE) |
+------------+
| 24.250000 |
+------------+
1 row in set (0.00 sec)

12. mysql> select TYPE,max(PRICE),min(PRICE) from Movie group by TYPE;


+--------+------------+------------+
| TYPE | max(PRICE) | min(PRICE) |
+--------+------------+------------+
| Drama | 49.00 | 19.00 |
| Horror | 69.00 | 69.00 |
| Comedy | 29.50 | 29.50 |
+--------+------------+------------+
3 rows in set (0.07 sec)

13. mysql> select RATING,avg(PRICE*QTY),sum(PRICE*QTY) from Movie group by RATING;


+--------+----------------+----------------+
| RATING | avg(PRICE*QTY) | sum(PRICE*QTY) |
+--------+----------------+----------------+
| G | 158.000000 | 158.00 |
| R | 97.500000 | 195.00 |
| PG | 343.000000 | 343.00 |
| PG13 | 177.000000 | 177.00 |
+--------+----------------+----------------+
4 rows in set (0.01 sec)

14. mysql> select ENTRY_DATE,count(*) from Movie group by ENTRY_DATE;


+------------+----------+
| ENTRY_DATE | count(*) |
+------------+----------+
| 2001-01-21 | 1 |
| 2001-01-27 | 1 |
| 2001-02-13 | 1 |
| 2010-11-21 | 1 |
| 2008-01-01 | 1 |
+------------+----------+
5 rows in set (0.00 sec)

15. mysql> select count(distinct type) from Movie;


+----------------------+
| count(distinct type) |
+----------------------+
| 3 |
+----------------------+
1 row in set (0.04 sec)

You might also like