Professional Documents
Culture Documents
Ex 3 Aggregate Functions
Ex 3 Aggregate Functions
Ex 3 Aggregate Functions
Aggregate Functions
Aim :
To create a program to implement aggregate function
COUNT, SUM, AVG, MAX, MIN, GROUPBY, HAVING in MySQL.
Syntax :
COUNT : Select count (*) from <table_name>;
SUM : select sum <attribute_name> from <table_name>;
AVG : select avg <attribute_name> from <table_name>;
MAX : select max <attribute_name> from <table_name>;
MIN : select min <attribute_name> from <table_name>;
GROUPBY : select <attribute_name> from <table_name>
groupby <attribute_name>;
HAVING : select <attribute_name> from <table_name>
groupby <attribute_name> having function();
ORDERBY : select <attribute_name> from <table_name>
groupby <attribute_name> having function() orderby
<attribute_name>;
STANDARD DEVIATION : select stddev(col. name) from
<table_name>;
QURIES:
mysql> select count(name) from marklist1;
+-------------+
| count(name) |
+-------------+
|
8|
+-------------+
86.6667 |
+------------+
1 row in set (0.00 sec)
4.7140 |
+---------------+
1 row in set (0.00 sec)
22.2222 |
+-----------------+
90 |
+------------+
1 row in set (0.00 sec)
80 |
+------------+
1 row in set (0.00 sec)
90 |
90 |
90 |
90 |
90 | 240 |
90 | 240 |
+-------+-------+-------+-------+-------+
2 rows in set (0.00 sec)
60 |
80 | NULL |
| depak | 80 |
60 |
80 | NULL |
| eaj | 70 |
70 |
70 | NULL |
| raj | 70 |
70 |
70 | NULL |
| ram | 80 |
80 |
80 | NULL |
| rat | 78 |
80 |
66 | NULL |
| ravi | 80 |
80 |
80 | NULL |
| ravl | 78 |
80 |
66 | NULL |
+-------+------+-------+-------+-------+
8 rows in set (0.02 sec)
60 |
80 | NULL |
| depak | 80 |
60 |
80 | NULL |
| eaj | 70 |
70 |
70 | NULL |
| raj | 70 |
70 |
70 | NULL |
| ram | 80 |
80 |
80 | NULL |
| rat | 78 |
80 |
66 | NULL |
| ravi | 80 |
80 |
80 | NULL |
| ravl | 78 |
80 |
66 | NULL |
+-------+------+-------+-------+-------+
8 rows in set (0.00 sec)
70 |
70 | NULL |
| raj | 70 |
70 |
70 | NULL |
| ravl | 78 |
80 |
66 | NULL |
| rat | 78 |
80 |
66 | NULL |
| anand | 80 |
60 |
80 | NULL |
| depak | 80 |
60 |
80 | NULL |
| ravi | 80 |
| ram | 80 |
80 |
80 |
80 | NULL |
80 | NULL |
+-------+------+-------+-------+-------+
8 rows in set (0.00 sec)
Result:
The above queries were successfully entered and verified.