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

MySQL Practical

SQL practical

Uploaded by

preeti
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
91 views

MySQL Practical

SQL practical

Uploaded by

preeti
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 21

MySQL

PRACTICALS
PRACTICAL 20
Problem statement : Create a student table with the student id, name and
marks as attributes where the student id is the Primary key.

Solution :
Source code :
create table student
-> (
-> studentid int primary key ,
-> name varchar (40),
-> marks int (10)
-> );
Screenshot :
PRACTICAL 21
Problem statement : In the table ‘student’ created in practical 20, insert
the details of new students.

Solution :
Source code :
mysql> insert into student values (1,'Reena',100);
mysql> insert into student values (2,'Gauri',101);
mysql> insert into student values (3,'Sonu',99);
mysql> insert into student values (4,'Priyanshu',78);
mysql> insert into student values (5,'Sanjeev',48);

Screenshot :
PRACTICAL 22
Problem statement : Write SQL command to get the details of the
students with marks more than 90.

Solution :
Source code :

mysql> select * from student where marks > 90 ;

Screenshot :
PRACTICAL 23
Problem statement : Write SQL command to Find the min, max, sum, and
average of the marks in a student marks table.

Solution :
Source code :
mysql> select min(marks) as MINIMUM_MARKS , max(marks) as
MAXIMUM_MARKS,sum(marks) as TOTAL_MARKS ,
-> avg (marks) as AVERAGE_MARKS from student ;

Screenshot :
PRACTICAL 24
Problem statement : Delete the details of a student table created in
Practical 23.

Solution :
Source code :

mysql> delete from student;

Screenshot :
PRACTICAL 25
Problem statement :. : Find the total number of customers from each
country in the table (customer ID, customer Name, country) using group
by.

Solution :
Source code :

mysql> select country , count(customer_name) as 'total_customers' from


customer
-> group by country;

Screenshot :
PRACTICAL 26
Problem statement :. : Write a SQL query to order the (student ID, marks)
table in descending order of the marks.

Solution :
Source code :

mysql> select* from student1 order by name DESC;

Screenshot :
PRACTICAL 27
Problem statement : for the given table ‘Hospital’ write SQL command to
display name all patient admitted in month of June.
PID PNAME ADMITDATE DEPERT FEES
01 REENA RAJ 26/06/2020 Dentist 1000
02 GAURI RAJ 23/05/2020 Cardio 2000
03 SONU RAJAT 15/05/2020 ENT 3000
04 SHEELA JAIN 06/09/2020 Neuro 4000

Solution :
Source code :

mysql> select * from hospital where monthname(admitdate) = 'June' ;

Screenshot :
PRACTICAL 28
Problem statement : for the given table ‘Hospital’ write SQL command to
Display patient name in upper case with year of admission.
PID PNAME ADMITDATE DEPERT FEES
01 REENA RAJ 26/06/2020 Dentist 1000
02 GAURI RAJ 23/05/2020 Cardio 2000
03 SONU RAJAT 15/05/2020 ENT 3000
04 SHEELA JAIN 06/09/2020 Neuro 4000

Solution :
Source code :
mysql> Select UPPER(pname) as 'patient_name', Year(admitdate) as
'admit_year' from hospital;

Screenshot :
PRACTICAL 29
Problem statement : for the given table ‘Hospital’ Create sql query to
display first four letters of the patient name along with length of their
name who admitted before June.
PID PNAME ADMITDATE DEPERT FEES
01 REENA RAJ 26/06/2020 Dentist 1000
02 GAURI RAJ 23/05/2020 Cardio 2000
03 SONU RAJAT 15/05/2020 ENT 3000
04 SHEELA JAIN 06/09/2020 Neuro 4000

Solution :
Source code :
mysql> Select LEFT (pname ,4) as 'pname', length (pname) as 'length'
-> from hospital
-> where month (admitdate) < 6;

Screenshot :
PRACTICAL 30
Problem statement : Create a table name student2 containing attributes
Roll no ,Name ,Gender ,Marks ,DOB ,Mobile no and Stream.
Solution :
Source code :
mysql> create table student2(
-> rollno int ,
-> name varchar (10),
-> gender char (4),
-> marks int ,
-> dob date ,
-> mobile int ,
-> stream char (15)
-> );
Screenshot :
PRACTICAL 31
Problem statement : Insert values in table created in practical 30 .
Solution :
Source code :

mysql> insert into student2 values (1,'Reena','f',100,'2006-04-


23',1111,'commerce');
mysql> insert into student2 values (2,'Teena','f',80,'2006-06-
23',2222,'commerce');
mysql> insert into student2 values (3,'Shivam','m',75,'2009-06-
06',3333,'science');
mysql> insert into student2 values (4,'Sonu','m',85,'2008-12-
22',4444,'vocational');
mysql> insert into student2 values (5,'Priya','f',95,'2008-02-
29',5555,'science');
mysql> insert into student2 values (6,'Payal','f',94,'2007-05-
25',6666,'humanities');
mysql> insert into student2 values (7,'Monu','m',39,'2008-12-
25',7777,'vocational');
mysql> insert into student2 values (8,'Sandeep','m',99,'2006-01-
23',8888,'commerce');
mysql> insert into student2 values (9,'Purvi','f',74,'2002-05-
13',9999,'humanities');
mysql> insert into student2 values (10,'Sanjana','f',44,'2002-06-
17',9998,'science');
Screenshot :
PRACTICAL 32
SUM()
Problem statement : Displays the sum of all the marks in table student2
Solution :
Source code : mysql> select sum(marks) from student2;
Screenshot :

Problem statement : Displays the sum of all the marks greater than 70 in
the table
Solution :
Source code : mysql> select sum(marks) from student2 where marks> 70;
Screenshot
PRACTICAL 33
AVG()
Problem statement : : Displays the average of all the marks in the table
student2.
Solution :
Source code : mysql> select avg(marks) from student2 ;
Screenshot :

Problem statement : : Displays the average of all the marks in the table
student2 who born before 1st April,2005..
Solution :
Source code :
mysql> select avg(marks) from student2 where dob < '2005-04-01';
Screenshot :
PRACTICAL 34
MAX()
Problem statement : . To display maximum marks from student2 table for
female only.
Solution :
Source code :
mysql> select max(marks) from student2 where gender = 'f';

Screenshot :
PRACTICAL 35
Problem statement : Write SQL command to get the details of the
students with marks more than 90.

Solution :
Source code :

mysql> select * from student where marks > 90 ;

Screenshot :
PRACTICAL 22
Problem statement : Write SQL command to get the details of the
students with marks more than 90.

Solution :
Source code :

mysql> select * from student where marks > 90 ;

Screenshot :

You might also like