You are on page 1of 6

PODAR INTERNATIONAL SCHOOL-VAPI

SNo Topic Marks

1 SQL Queries (pen and paper) 7

2 Practical File – 12 SQL Queries 2

3 Final Project Submission 3

4 Viva 3

Total 15

:SAMPLE TABLES FOR QUERY PRACTICE:


TABLE-1

1. Create a student table with the student id, name, and marks as attributes where the student id is the primary
Key.
2. Insert the details of a new student in the above table.
3. Delete the details of a student in the above table.
4. Use the select command to get the details of the students with marks more than 80.
5. Find the min, max, sum, and average of the marks in a student marks table.
6. Find the total number of customers from each country in the table (customer ID, customer
Name, country) using group by.
7. Write a SQL query to order the (student ID, marks) table in descending order of the marks
8. Write a SQL query to display the marks without decimal places, display the reminder after diving marks by 3
and display the square of marks
9. Write a SQL query to display names into capital letters, small letters, display frist 3 letters of name, display
last 3 letters of name, display the position the letter A in name
10. Remove extra spaces from left, right and both sidesfrom the text – ” Informatics Practices Class XII “.
11. Display today’s date in “Date/Month/Year” format.
12. Display dayname, monthname, day, dayname, day of month, day of year for today’s date.
Answers

[1] Create table student - create table student


(studentid int(3) primary key,
name varchar(20) not null,
marks decimal(5,2));

[2] Inserting records

Table data:

INFORMATICS PRATICES-PRACTICAL PRACTICE NISHA SHROFF


PODAR INTERNATIONAL SCHOOL-VAPI

[3] Deleting records


delete from student where studentid=5;

[4] Fetching record with criteria


select * from student where marks>80;

[5] Maximum, Minimum, Sum and Average of marks


select max(marks), min(marks), sum(marks) , avg(marks) from student;

[6] Group by
select country, count(customer_id) from customer group by country;
[7] Sorting in descending order
select * from student order by marks desc;

INFORMATICS PRATICES-PRACTICAL PRACTICE NISHA SHROFF


PODAR INTERNATIONAL SCHOOL-VAPI

[8] Math functions


select round(marks,0),mod(marks,3),pow(marks,2) from student;

[9] Text functions


select ucase(name),lcase(name),left(name,3),right(name,3),instr(name,'a') from student;

INFORMATICS PRATICES-PRACTICAL PRACTICE NISHA SHROFF


PODAR INTERNATIONAL SCHOOL-VAPI

[10] Text Functions


select ltrim(" Informatics Practices Class XII ") "Left Spaces", rtim(" Informatics Practices Class
XII ") "Right Trim", trim(" Informatics Practices Class XII ");

[11] Date function in MySQL


select concat(date(now()),concat("/",concat(month(now()),concat("/",year(now())))));

[12]
select
dayname(now()),monthname(now()),day(now()),dayname(now()),dayofmonth(now()),dayofyear(now());

TABLE-2
1. Create a database named PracticalExam and open database. 1
2. Create following table – “Candidate” 1
 candidateid – int(4), Primary Key
 candidatename – varchar(20) not null
 batch – varchar(10)
 examdate – date
 marks – float
 stream – varchar
3. Insert 10 records into the table as per your choice, one sample is as following (Use batches as: Batch1, Batch2,
Batch3) : 1
 1201, ‘Sagar Patel’, ‘Batch1’, ‘2022/02/25’, 14, ‘commerce’
4. Write queries based on the table candidate 4
 Dispay the square of marks for candidates
 Display candidateid, cadnidatename, examdate, marks without decimalplaces for batch1 and batch2
students
 Display maximum, minimum and sum of marks of candidates
 Display number students from commerce stream
 Display the candidate names into capitals
 Display first two letters of candidatenames
 Display the average marks of stduents for each batch

INFORMATICS PRATICES-PRACTICAL PRACTICE NISHA SHROFF


PODAR INTERNATIONAL SCHOOL-VAPI

 Display the name of the day of week including candidatename, batch, marks and stream
Solution
create database practicalexam
use practicalexam;
create table candidate
(candidateid int(4) primary key,
candidatename varchar(20) not null,
batch varchar(10),
examdate date,
mark float,
stream varchar(10));
insert into candidate values
(1201,'Sagar Patel','Batch 1','2022/02/25',14.5,'commerce'),
(1202,'Smita Patel','Batch 2','2022/02/24',13.5,'science'),
(1203,'Aman Parmar','Batch 3','2022/02/20',12,'commerce'),
(1204,'Sapna Vyas','Batch 2','2022/02/25',10.5,'science'),
(1205,'Man Pandya','Batch 1','2022/02/24',11,'commerce'),
(1206,'Dinesh Parmar','Batch 2','2022/02/25',14,'commerce'),
(1207,'Sonam Solanki','Batch 1','2022/02/25',13,'science'),
(1208,'Manish Joshi','Batch 2','2022/02/23',14.5,'commerce'),
(1209,'Mahendra Gohel','Batch 1','2022/02/25',14,'commerce'),
(1210,'Smita Chava','Batch 3','2022/02/25',15,'science');

Queries:

1. select power(marks,2) from candidate;


2. select candidateid,candidatename, examdate, round(marks) from candidate where batch='Batch1'
or Batch='Batch 2';
3. select max(marks), min(marks), sum(marks) from candidate;
4. select count(candidateid) from candidate where stream='commerce';
5. select upper(candidatename) from candidate;
6. select left(candidatename,2) from candidate;
7. select batch,avg(marks) from candidate group by batch;
8. select candidatename, batch, marks, stream, dayname(examdate) from candidate;
TABLE-3

Consider the following tables Employee22 and Department and answer the given questions?

Employee 22

No Name Salary Zone Age Grade Dept


1 Mukul 30000 West 28 A 10
2 Kritika 35000 Centre 30 A 10
3 Naveen 35000 West 40 NULL 20
4 Uday 38000 North 38 C 30
5 Nupur 32000 East 26 NULL 20
6 Mukesh 22000 South 41 B 40
Department
Dept DName MINSAL MAXSAL HOD

INFORMATICS PRATICES-PRACTICAL PRACTICE NISHA SHROFF


PODAR INTERNATIONAL SCHOOL-VAPI

10 SALES 25000 35000 1


20 FINANCE 30000 36000 5
30 ADMIN 25000 40000 7
1. To display all records from department table.
mysql> select * from Department;
2. Write a command in SQL to display the details of employees who are below 30 years of age?
mysql> select * from Employee22 where age<30;
3. Write a command in SQL to display the Name,Grade of
mysql> select Name,Grade from Employee22 where Grade Is null;
4. Write a query to select all zones.
mysql> select distinct Zone from Employee22;
5. Write a query to select no,name and salary whose depat no is 20 and salary is greater than 30000.
mysql> select No,Name,Salary from Employee22 where Dept=20 and Salary>30000;
6. Write a query to display all the details of employees whose salary is between 25000 to 35000
mysql> select * from Employee22 where Salary between 25000 and 35000;
7. Write a query to display name,salary and age of employees whose name start with N
mysql> select Name,Salary,Age from Employee22 where Name like 'N%';

INFORMATICS PRATICES-PRACTICAL PRACTICE NISHA SHROFF

You might also like