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

SQL(1-4)final

Uploaded by

kingmugunthan2
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

SQL(1-4)final

Uploaded by

kingmugunthan2
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

COMPUTER SCIENCE-RECORD

Sl.No. NAME OF THE PROGRAM


1 Queries to create table ,insert data and select rows based on condition
2 Queries using MySQL functions
3 Queries using order by, group by clause and aggregate functions
4 Queries to modify data and update data in table

SQL1: Queries to create table, insert data and select rows based on condition
Question:
Consider the following MOVIE table and write the SQL queries based on it.
Movieid Moviename Type Releasedate Productioncost Businesscost
M001 The Kashmir Action 2022/01/26 1245000 1300000
files
M002 Attack Action 2022/01/28 1120000 1250000
M003 Loop Lapeta Thriller 2022/02/01 250000 300000
M004 Badhai Do Drama 2022/02/04 720000 680000
M005 Shabaash Biography 2022/02/04 1000000 800000
Mithu
M006 Gehraiyaan Romance 2022/02/11 150000 120000

I. Create the given movie table.


II. Insert given data into movie table.
III. Display all details in movie table;
IV. Display the type of movies.
V. Display movieid, moviename, total_eraning by showing the business done by the movies.
Claculate the business done by movie using the sum of productioncost and businesscost.
VI. Display movieid, moviename and productioncost for all movies with productioncost greater
thatn 150000 and less than 1000000.
VII. Display the movie of type action and romance.
VIII. Display the list of movies which are going to release in February, 2022.

Answer:
I. Mysql>Create table movie(movieid char(5),moviename varchar(25),type varchar(20), Releasedate
date, productioncost integer, businesscost integer);
II. Mysql>insert into movie values(“M001”, ”The Kashmir files”, ”Action”, str_to_date(“2022-01-26”,
%Y-%m-%d),1245000,1300000);

Mysql>insert into movie values(“M002”, ”Attack”, ”Action”, str_to_date(“2022-01-28”, %Y-%m-


%d),112000,1250000);

Mysql>insert into movie values(“M003”, ”Loop lapeta”, ”Thriller”, str_to_date(“2022-02-01”, %Y-


%m-%d),250000,3000000);

Mysql>insert into movie values(“M004”, ”Badhai Do”, ”Drama”, str_to_date(“2022-02-04”, %Y-


%m-%d),720000,680000);

Mysql>insert into movie values(“M005”, ”Shabaash Mithu”, ”Biography”, str_to_date(“2022-02-


04”, %Y-%m-%d),1000000,8000000);

Mysql>insert into movie values(“M006”, ”Gehraivaan”, ”Biography”, str_to_date(“2022-02-11”,


%Y-%m-%d),1200000,1500000);

III.

IV.
V.

VI.

VII.

VIII.

________________________________________________________________

SQL2: Queries using MySQL functions


Question:
I. Write a query to display cube of 5.
II. Write a query to display the number 563.854741 rounding off to the next hundred.
III. Write a query to display today’s date into DD.MM.YYYY format.
IV. Write a query to return square root of numeric expression.
V. Write a query to return the length of a string.
VI. Write a query to return the substring as specified.
Answer:

I.

II.

III.

(OR)

IV.
V.

VI.

_______________________________________________________________

SQL3: Queries using order by, group by clause and aggregate functions

Question:

Consider the following table stock table to answer the queries:

Itemno Itemname Dcode Qty Unitprice Stockdate


S003 Gelpen 101 150 15 2018/03/18
S002 Pencil 102 125 5 2018/02/25
S006 Eraser 101 200 3 2018/01/12
S001 Sharpner 103 210 5 2018/06/11
S004 Compass 102 60 35 2018/05/10
S009 A4papers 102 160 5 2018/07/17
S005 Ballpen 102 100 10 2018/04/22

I. Display all the items in the ascending order of stockdate.


II. Display maximum price of items for each dealer individually as per dcode from stock.
III. Display all the items in descending orders of itemname.
IV. Display average price of items for each dealer individually as per dcode from stock which
average price is more than 5.
V. Display the sum of quantity for each dcode.
Answer:

I.

II.

III.

IV.
V.

________________________________________________________

SQL4: Queries to modify data and update data in table


Question:
I. Write the query to create new table(newstock1) and insert data from another table(stock).
II. Modify data in table(newstock1). Change the itemname from gelpen to fountain pen.
III. Delete the rows whose quantity is less than 150 from newstock1 table.
IV. Add one column (No.of stocks sold) in newstock1 table.
V. Truncate the table (newstock1) and then drop table(newstock1).
Answer:
I.

II.
III.

IV.

V.

________________________________________________________________________________

You might also like