Download as pdf or txt
Download as pdf or txt
You are on page 1of 9

You don’t want to write the instructions which are in red colour.

Program number you


can start from the last program’s next number. Probably Program 16.

Program 1 : Queries Set 1(Based on functions):-


1. Write a query to find the cube of 5.
2. Write a query to display the number 557.754731 rounding off to 2 decimal places.
3. Write a query to find the square root of 500.
4. Write a query to display “put” from the word “computer”.
5. Write a query to display today’s date into ‘DD-MM-YYYY’ format.
6. Write a query to display ‘DIA’ from ‘MEDIA’.
7. Write a query to display “St. Anthony’s” into lowercase.
8. Write a query to find the number of characters in the string “I love India”.
9. Write a query to find the remainder after division of 346 by 3.
10.Write a query to illustrate the difference between now() and sysdate().

Output (Write on the output side . For outputs you have to draw the table structure.
Format as shown below.)
pow(5,2)
25
1. select pow(5,2);

2. select round(557.754731 ,2);

3. select sqrt(500);

4. select substr('Computer', 4,3);

1
5. select concat(day(now()),concat('-',month(now()), concat('-',year(now())))) as "Date";

6. select right("MEDIA",3);

7. select lower("St. Anthony’s");

8. select length("I love India");

9. select mod(346,3);

10.select now(),sleep(3), sysdate();

Program 2 : Queries Set 2 (Database- Fetching Records from the table Salesman):-
Consider the following table Salesman details and write queries to answer the following
questions.
Table name : salesman
Primary key: salesman_id

2
salesman_id | name | city | commission
-------------+------------+----------+------------
5001 | James Hoog | New York | 0.15
5002 | Nail Knite | Paris | 0.13
5005 | Pit Alex | London | 0.11
5006 | Mc Lyon | Paris | 0.14
5007 | Paul Adam | Rome | 0.13
5003 | Lauson Hen | San Jose | 0.12
5008 | Park Maax | Rome | 0.12

1. Display all the information from salesman.


2. Return salesperson's name and city who live in the city of 'Paris'.
3. List all the details of salespersons whose commission greater than 0.13.
4. Return salesperson's name and commission whose city name starts with ‘L’.
5. List the id, name and city of salesperson who is getting the highest commission.
6. Give the count of employees who live in the city of ‘Rome'

Output (Write on the output side)


1. select * from salesman;

2. select name, city from salesman where city='Paris';

3. select * from salesman where commission>0.13;

4. select name, commission from salesman where city like'L%';

3
5. select salesman_id, name, city from salesman where commission=(select
max(commission) from salesman);

6. select count(*) from salesman where city='Rome';

Program 3 : Queries Set 3 (DDL and DML commands implementation):-

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:
o It should have a column TeamID for storing an integer value between 1 to 9, which
refers to unique identification of a team.
o Each TeamID should have its associated name (TeamName), which should be a string
of length not less than 10 characters.
o Using table level constraint, make TeamID as the primary key.
o Show the structure of the table TEAM using a SQL statement.
o As per the preferences of the students four teams were formed as given below. Insert
these four rows in TEAM table:
▪ Row 1: (1, Tehlka)
▪ Row 2: (2, Toofan)
▪ Row 3: (3, Aandhi)
▪ Row 3: (4, Shailab)
o Show the contents of the table TEAM using a DML statement.
3. Now create another table MATCH_DETAILS and insert data as shown below. Choose
appropriate data types and constraints for each attribute.

4
Output (Write on the output side)
1. create database sports;

2. create table team (teamid int ,teamname varchar(10) not null, primary key(teamid));

a. Inserting data
insert into team values(1,'Tehlka');
insert into team values(2,'Toofan');
insert into team values(3,'Aandhi');
insert into team values(4,' Shailab ');

b. select * from team;

3. create table match_details(matchid varchar(2) primary key,matchdate date, firstteamid int


references team(teamid), secondteamid int(1) references team(teamid),firstteamscore
int(3),secondteamscore int(3));

5
After inserting values

Program 4 : Queries Set 4 (Based on two tables in the above example team and
match_details):-

1. Display the matchid, teamid, teamscore who scored more than 70 in first inning along
with team name.
2. Display matchid, teamname and secondteamscore between 100 to 160.
3. Display matchid, teamnames along with matchdates.
4. Display unique team names
5. Display matchid and matchdate played by Anadhi and Shailab.

Output (Write on the output side)

1. select match_details. matchid, match_details.firstteamid, team.teamname,


match_details.firstteamscore from match_details, team where
match_details.firstteamid=team.teamid and match_details.firstteamscore>70;

(Draw the corresponding table here)

2. select matchid, teamname, secondteamscore from match_details, team where


match_details.secondteamid=team.teamid and match_details.secondteamscore between
100 and 160;

6
3. select matchid,teamname,firstteamid,secondteamid,matchdate from match_details, team
where match_details.firstteamid=team.teamid;

4. select distinct (teamname) from match_details, team where


match_details.firstteamid=team.teamid;

5. select matchid,matchdate from match_details, team where


match_details.firstteamid=team.teamid and team.teamname in (‘Aandhi’,’Shailab’);

Program 5 : Queries Set 5 (Group by , Order By):-


Consider the following table stock table to answer the queries:

7
1. Display all the items in the ascending order of stockdate.
2. Display maximum price of items for each dealer individually as per dcode from stock.
3. Display all the items in descending orders of item names.
4. Display average price of items for each dealer individually as per dcode from stock which
average price is more than 5.
5. Display the sum of quantity for each dcode.

Output (Write on the output side)


1. select * from stock order by stockdate;

2. select dcode, max(unitprice) from stock group by dcode;

3. select * from stock order by item desc;

4. select dcode,avg(unitprice) from stock group by dcode having avg(unitprice)>5;

8
5. select dcode, sum(qty) from stock group by dcode;

Remaining are connectivity programs…That I will send you on Wednesday. Write


this much today itself.

Ashalakshmi.R
(05.11.2023)

You might also like