Find the min, max, sum, and average of the marks in a student marks table.
Queries for Aggregate functions- SUM( ), AVG( ), MIN( ), MAX( ), COUNT( )
Table Name: Student1920
mysql> use school;
Database changed
mysql> create table student1920
(RollNo int(2) primary key,
Name char(20),
Class char(3),
DOB date,
Gender char(1),
City char(10),
Marks int(3)
);
insert into student1920 values(1,"Nanda","X","1995/06/06","M","Agra",551);
insert into student1920 values(2,"Saurabh","XII","1993/05/07","M","Mumbai",462);
insert into student1920 values(3,"Sanal","XI","1994/05/06","F","Delhi",400);
insert into student1920 values(4,"Trisla","XII","1995/08/08","F","Mumbai",450);
insert into student1920 values(5,"Store","XII","1995/10/08","M","Delhi",369);
insert into student1920 values(6,"Marisla","XI","1994/12/12","F","Dubai",250);
insert into student1920 values(7,"Neha","X","1995/12/08","F","Moscow",377);
insert into student1920 values(8,"Nishant","X","1995/06/12","M","Moscow",489);
a. Find the average marks of the students in student1920 table.
Solution:- SELECT avg(marks) from student1920;
b. Find the minimum marks of a female students in student1920 table.
Solution:- SELECT name, min(marks) FROM student1920 WHERE Gender="F";
c. Find the maximum marks of a male students in student1920 table.
Solution:- SELECT name, max(marks) FROM student1920 WHERE Gender="M";
d. Find the total marks of those students who work in Delhi city.
Solution:- SELECT sum(marks) FROM student1920 WHERE city="Delhi";
e. Find the number of tuples in the student1920 relation.
Solution:- SELECT count(*) FROM student1920;
No comments:
Post a Comment