0% found this document useful (0 votes)
62 views13 pages

SQL - Lab - Exercise (16 - To - 20) (1) (AutoRecovered)

Uploaded by

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

SQL - Lab - Exercise (16 - To - 20) (1) (AutoRecovered)

Uploaded by

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

MY SQL

Instructions to write record:

1. Use a pencil to draw the table on the left-hand side of your record note.

2. On the right hand side write the Aim,Scenario and result

3. Take a printout of the SQL queries and output should be attached in record

Ex no.16 Queries Set 1 (DDL Commands)


Aim:

To execute SQL Queries in MySql for the given scenario and display the result

Scenario:

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:

1. Create a database “Sports”.


2. Create a table “TEAM” with following considerations:

a. It should have a column TeamID for storing an integer value between 1 to 9, which refers
to unique identification of a team.
b. Each TeamID should have its associated name (TeamName), which should be a string
of length not more than 10 characters.
c. Using 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:
i. Row 1: (1, Titan)
ii. Row 2: (2, Rockers)
iii. Row 3: (3, Magnet)
iv. Row 4: (4, 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.

Second Team
MatchID MatchDate First TeamID Second TeamID First Team Score
Score
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
SQL Queries and Output:

1.Database Creation:

Query:

Output:

2. TEAM Table Creation:


a, b &c. Creation of table

Query:

Output:
(a),(b)&(c)

d. Display the structure of table

Query:

Output:
e. Inserting into table

Query:

Output:

f. To show records

Query:

Output:

g. Creation of new table

Query:
Output:

Result:

The SQL commands for the given scenario is written, executed and the output verified

EX.No.17 Queries Set 2 (Database Fetching records)


Aim:

To execute SQL Queries in MySql for the given scenario and display the result
Scenario:

Consider the following MOVIE table and write the SQL queries based on it.

Release Production Business


Movie_ID MovieName Type Date Cost Cost
M001 The Kashmir Files Action 2022-01-26 1245000 1300000
M002 Attack Action 2022-01-28 1120000 1250000
M003 Looop Lapeta Thriller 2022-02-01 250000 300000
M004 Badhai Do Drama 2022-02-04 720000 68000
M005 Shabaash Mithu Biography 2022-02-04 1000000 800000

1. Display all the records from the table movie.


2. Display the different type of movies.
3. Display movieid, moviename, total earning by calculating business done by movie using the
sum of production cost and business cost .
4. Display movieid, moviename and productioncost for all movies with productioncost greater than
150000 and less than 1000000.
5. Display the movie of type action and romance.
6. Display the list of movies which are going to release in February, 2022.

SQL Queries and Output:


1.Query:

Output:

2.Query:

Output:
3.Query:

Output:

4. Query:

Output:

5.Query:

Output:
6.Query:

Output:

Result:

The SQL commands for the given scenario is written, executed and the output verified

EX.No.18 Queries set 3 (Based on Two Tables)


Aim:
To execute SQL Queries in MySql for the given scenario

Scenario:
In a company database, there are two tables given below :
Table:JOB

JOBID JOBTITLE SALARY

101 President 200000

102 Vice President 125000

103 Administration Assistant 80000

104 Accounting Manager 70000

105 Accountant 65000

106 Sales Manager 80000


EMPI NAME SALES JOBID
D

E1 SUMIT SINGH 1100000 102

E2 VIJAY 1300000 101 Table:Employee

E3 AJAY 1400000 103

E4 MOHIT SINGH 1250000 102

E5 SHAILU 1450000 103

Write SQL Queries for the following :

1. To display employee ids, names of employees, job ids with corresponding job titles.
2. To display names of employees, sales and corresponding job titles who have achieved sales more than
1300000.
3. To display names and corresponding job titles of those employees who have 'SINGH' (anywhere) in
their names.
4. Show employee name ,job title and salary of those employees who are working in any one of the
mentioned job( President,Vice President, Accountant)
5. Write SQL command to change the JOBID to 104 of the EMPLOYEE with ID as E4 in the table
'EMPLOYEE'.

SQL Queries and Output:


1. QUERY:

OUTPUT:

2. QUERY:

OUTPUT:

3. QUERY:
OUTPUT:

4.QUERY:

OUTPUT:

5. QUERY:

OUTPUT:

Result:

The SQL commands for the given scenario is written, executed and the output verified

Ex.no.19 Queries Set 4 (Group by , Order By)


Aim:
To execute SQL Queries in MySql for the given scenario

Scenario:
Consider the following ‘stock’ table to answer the queries:

Itemno item dcode qty price stockdate


S005 Ballpen 102 100 10 2018-04-22
S003 Gel Pen 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 110 5 2018-06-11
S004 Compass 102 60 25 2018-05-10
S009 A4 Papers 102 160 5 2018-07-15

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


2. Display number of items,total price for each dealer individually as per dcode from stock.
3. Display all the items in descending orders of itemnames.
4. Display maximum price of items for each dealer individually as per dcode from stock which has
maximum price more than 10.
5. Display the sum of quantity for each dcode from stock which has price between 10 to 30.

SQL Queries and Output:


1.QUERY:

OUTPUT:

2.QUERY:

OUTPUT:

3.QUERY:

OUTPUT:
4.QUERY:

OUTPUT:

5.QUERY:

OUTPUT:

Result:

The SQL commands for the given scenario is written, executed and the output verified

Queries Set 5 (Based on Functions)


Aim:
To execute SQL Queries in MySql for the given scenario

Scenario:

1. Write a query to display cube of 5.


2. Write a query to display the number 563.854741 rounding off to the next hnudred.
3. Write a query to display “put” from the word “Computer”.
4. Write a query to display today’s date into DD.MM.YYYY format.
5. Write a query to display ‘DIA’ from the word “MEDIA”.
6. Write a query to display moviename – type from the table movie.
7. Write a query to display first four digits of productioncost.
8. Write a query to display last four digits of businesscost.
9. Write a query to display weekday of release dates.
10. Write a query to display dayname on which movies are going to be released.

SQL Queries and Output:


1.QUERY:
OUTPUT:

2.QUERY:

OUTPUT:

3.QUERY:

OUTPUT:

4.QUERY:

OUTPUT:

5.QUERY:

OUTPUT:

6.QUERY:

OUTPUT:

7.QUERY:

OUTPUT:
8.QUERY:

OUTPUT:

9.QUERY:

OUTPUT:

10.QUERY:

OUTPUT:

Result:

The SQL commands for the given scenario is written, executed and the output verified

You might also like