Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
25 views

Aggregate Functions

Aggregate functions perform calculations on groups of rows and return a single value. Some common aggregate functions include: 1. SUM(), which returns the total of a numeric column. 2. AVG(), which returns the average of a numeric column. 3. MAX(), which returns the highest value in a column. 4. MIN(), which returns the lowest value in a column. 5. COUNT(), which returns the number of rows that match a condition. COUNT(*) returns the number of rows in a table regardless of values.

Uploaded by

dalkota mota
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views

Aggregate Functions

Aggregate functions perform calculations on groups of rows and return a single value. Some common aggregate functions include: 1. SUM(), which returns the total of a numeric column. 2. AVG(), which returns the average of a numeric column. 3. MAX(), which returns the highest value in a column. 4. MIN(), which returns the lowest value in a column. 5. COUNT(), which returns the number of rows that match a condition. COUNT(*) returns the number of rows in a table regardless of values.

Uploaded by

dalkota mota
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 20

AGGREGATE FUNCTIONS

Prepared by Ajitha Kumari, M.Tech (PGT )SJCS,KK


AGGREGATE FUNCTIONS
• Aggregate Functions OR Group functions work upon group
of rows ,rather than on single rows.
• Or
• An aggregate function performs a calculation on multiple
values and return a single value
AGGREGATE FUNCTIONS
1. sum()
2. Avg()
3. Max()
4. Min()
5. Count()
6. Count(*)
STUDENT TABLE
SUM()
• This function returns the sum of values in a
given column or expression
Syntax:
Select sum(distinct /All ) column
name> from table name;
SUM()
• Example
• SUM()
• mysql> select sum(fees) from student;
• +-----------+
• | sum(fees) |
• +-----------+
• | 62400 |
• +-----------+
• 1 row in set (0.00 sec)
AVG()
• This function computes the average of the given data
Syntax:
select avg(distinct/ all /column name from table name;
AVG()
• AVG()
• mysql> select avg(fees) from student;
• +-----------+
• | avg(fees) |
• +-----------+
• | 6240.0000 |
• +-----------+
• 1 row in set (0.00 sec)
MAX()
• This function refers the maximum wise from a given column or expression
• Syntax:
• Select max(distinct/ All column name from table name;
MAX()
• mysql> select max(fees) from student;
• +-----------+
• | max(fees) |
• +-----------+
• | 9000 |
• +-----------+
• 1 row in set (0.00 sec)
MIN()
• Min function returns the minimum value of an expression

• Syntax:
• Select min(aggregate expression) from table name
MIN()
• MIN()

• mysql> select min(fees) from student;
• +-----------+
• | min(fees) |
• +-----------+
• | 3200 |
• +-----------+
• 1 row in set (0.00 sec)
COUNT AND COUNT(*)
• Count function returns the count of an expression
• Syntax:
• Select count (aggregate_expression) from tables

• This is the column or expression whose non null values will be counted.
DIFFERENCE BETWEEN COUNT AND COUNT (*)
• COUNT(expression)
• The COUNT(expression) returns the number of rows that do not contain NULL
values as the result of the expression.

• COUNT(DISTINCT expression)
• The COUNT(DISTINCT expression) returns the number of distinct rows that do
not contain NULL values as the result of the expression.
COUNT(*)
• mysql> select count(*) from student;
• +----------+
• | count(*) |
• +----------+
• | 11 |
• +----------+
• 1 row in set (0.00 sec)
COUNT(FIELD NAME)
• mysql> select count(stid) from student;
• +-------------+
• | count(stid) |
• +-------------+
• | 10 |
• +-------------+
• 1 row in set (0.00 sec)
SELECT DISTINCT column1, column2,.....columnN FROM table_name WHERE [condition]
SELECT DISTINCT column1, column2,.....columnN FROM table_name WHERE [condition]
SELECT DISTINCT column1, column2,.....columnN FROM table_name WHERE [condition]

DISTINCT
• The SQL DISTINCT keyword is used in conjunction with the SELECT statement
to eliminate all the duplicate records and fetching only unique records.
Syntax:
SELECT DISTINCT column1, column2,.....columnN
FROM table_name
WHERE [condition]
DISTINCT
• mysql> select distinct(fees) from student;
• +------+
• | fees |
• +------+
• | 9000 |
• | 8000 |
• | 3200 |

You might also like