0% found this document useful (0 votes)
150 views8 pages

MySQL Query Exercises

The document contains example queries to retrieve data from different tables in a MySQL database. It includes queries to select, update, insert and aggregate data based on conditions, sorting, grouping and joins. The tables include patient details, student records and corona case statistics.

Uploaded by

Chetna Sharma
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)
150 views8 pages

MySQL Query Exercises

The document contains example queries to retrieve data from different tables in a MySQL database. It includes queries to select, update, insert and aggregate data based on conditions, sorting, grouping and joins. The tables include patient details, student records and corona case statistics.

Uploaded by

Chetna Sharma
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

PRACTICAL QUESTIONS:-

Q1.
Consider the table patient with the above data and
define the first column as PID as primary key, feed all the
records in the table and then answer the following
queries in MySQL:-
a) To display the names of the patient whose age
is more than 60 yrs
CODE: Select p_name from patient where age>60;

OUTPUT :
b)To display maximum and minimum charges.
CODE: Select max(charges), min(charges) from
patient;

OUTPUT:
c) To display name of the disease and the total
charge on the basis of disease.
CODE: Select disease, sum(charges) from patient
group by disease;

OUTPUT:
d)To display details of the given table in
the descending order of age.
CODE: Select*from patient order by age desc;

OUTPUT:
e)To display the information of the patient on the
basis of increasing order of fees.
CODE: Select *from patient order by charges asc;

OUTPUT:
f) To display the names of the patient starting with
M. CODE: Select p_name from patient where
p_name like ‘M%’;
OUTPUT:
g) To display the disease wise count of all
patient whose fee charges are more than
Rs.50.
CODE: Select disease ,count(*) from patient where
charges>50 group by disease;

OUTPUT:
Q2.

Consider the display student with the above data


and define the first column SID as primary key, feed
all the records in the table and then answer the
following queries in MySQL:-
a) To count the number of students in each section.
CODE: Select section,count(*) from student group
by section;

OUTPUT:
b) To display the names of the student who get
“excellent “remark in their project.
CODE:Select name from student where
proj_rem=’Excellent’;

OUTPUT:
c) To increase the marks of the student “vivek” in CS
by 5.
CODE:Update student set cs=cs+5 where
name=’vivek’;
OUTPUT:

d) To display the names of the students ending with


“a”.
CODE:Select name from student where name like
’%a’;

OUTPUT:
e) To display the details of the student whose
IT marks are in the range 25 to35.
CODE: Select * from student where IT between 25
and 35;
OUTPUT:

f) To display the name of the student who


secured maximum marks in IT.
CODE:Select name,IT from student where
IT=(select max(IT) from student);

OUTPUT:
g) To insert a new row with values (105,’shreya’,
12,’d’, 40, 38,’excellent’).

CODE: Insert into student values(105,’shreya’,


12,’d’, 40, 38,’excellent’);

OUTPUT:
Q3.

Consider the table corona with the above data and


define the first column as SID as primary key, feed all
the records in the table and then answer the
following queries in MySQL:-
a) To display the names of the states who’s
starting with letter ‘D’.
CODE:Select State from corona where state like
‘D%’;

OUTPUT:
b) To display total number of death during
corona. CODE: select sum(Death) as
Total_death from corona;

OUTPUT:
c) To increase the number of cases by 100.
CODE: Update corona set cases=cases+100;
OUTPUT:
d) To display the state with the lowest number
of corona case.
CODE:Select State,cases from corona where
cases=(select min(cases) from corona;

OUTPUT:
e) To add a new column “recovery “with integer as
data type.
CODE:Alter table corona add(Recovery int);

OUTPUT:
f) to display the names of the states who are having
cases between 2000 to 4000.
CODE:Select state from corona where cases between
2000 and 4000;

OUTPUT:

You might also like