0% found this document useful (0 votes)
8 views3 pages

7

The document outlines Experiment No. 7, which focuses on studying and implementing aggregation functions such as COUNT, MIN, MAX, SUM, and AVG in a database context. It provides definitions, syntax, and examples for each function, highlighting their usage in SQL queries. The conclusion confirms the successful implementation of these aggregation functions.

Uploaded by

VMV CREATION
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)
8 views3 pages

7

The document outlines Experiment No. 7, which focuses on studying and implementing aggregation functions such as COUNT, MIN, MAX, SUM, and AVG in a database context. It provides definitions, syntax, and examples for each function, highlighting their usage in SQL queries. The conclusion confirms the successful implementation of these aggregation functions.

Uploaded by

VMV CREATION
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/ 3

Experiment No.

AIM: Study and implement aggregation functions like min, max, avg, sum, count.

THEORY:

Aggregate functions allow us to easily produce summarized data from our database.

COUNT
The COUNT function returns the total number of values in the specified field. It works on both
numeric and non-numeric data types. All aggregate functions by default exclude nulls values
before working on the data.

COUNT (*) is a special implementation of the COUNT function that returns the count of all the
rows in a specified table. COUNT (*) also considers Nulls and duplicates.

Create the customer_id[int]


table first_name[varchar(100)]
last_name[varchar(100)]
Customers age[int]
country[varchar(100)]

Insert data

Syntax / SELECT COUNT(col_name) SELECT COUNT(first_name) FROM


Example FROM table_name WHERE Customers WHERE customer_id= 2;
condition;

DISTINCT Keyword
The DISTINCT keyword that allows us to omit duplicates from our results. This is achieved by
grouping similar values together.
Syntax / SELECT DISTINCT col_name SELECT DISTINCT customer_id FROM
Example FROM table_name; Customers;

MIN function
The MIN function returns the smallest value in the specified table field.

As an example, let’s suppose we want to know the year in which the oldest movie in our library
was released, we can use MySQL’s MIN function to get the desired information.

Syntax / SELECT MIN(col_name) FROM SELECT MIN(customer_id) FROM


Example table_name; Customers;

MAX function
Just as the name suggests, the MAX function is the opposite of the MIN function. It returns the
largest value from the specified table field.

Let’s assume we want to get the year that the latest movie in our database was released. We can
easily use the MAX function to achieve that.

Syntax / SELECT MAX(col_name) FROM SELECT MAX(customer_id) FROM


Example table_name; Customers;

SUM function

Suppose we want a report that gives total amount of payments made so far. We can use the
MySQL SUM function which returns the sum of all the values in the specified column. SUM
works on numeric fields only. Null values are excluded from the result returned.

Syntax / SELECT SUM(col_name) FROM SELECT SUM(customer_id) FROM


Example table_name; Customers;
AVG function
MySQL AVG function returns the average of the values in a specified column. Just like the
SUM function, it works only on numeric data types.

Syntax / SELECT AVG(col_name) FROM SELECT AVG(customer_id) FROM


Example table_name; Customers;

Conclusion: Thus we have successfully studied and implemented aggregation functions


like min, max, avg, sum, count.

You might also like