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

SQL Functions: MIN, MAX, COUNT, SUM, AVG

Uploaded by

beguenine
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)
7 views3 pages

SQL Functions: MIN, MAX, COUNT, SUM, AVG

Uploaded by

beguenine
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

National Specialized Institute for Vocational Training MASCARA

DB - S2 SQL (Structured Query Language)

SQL MIN() and MAX()


The MIN() function returns the smallest value of the selected column.
The MAX() function returns the largest value of the selected column.
Syntax

SELECT MIN(column_name)
FROM table_name
WHERE condition;

SELECT MAX(column_name)
FROM table_name
WHERE condition;

MIN Example: Find the lowest price in the Price column:


SELECT MIN(Price)
FROM Products;

MAX Example: Find the highest price in the Price column:


SELECT MAX(Price)
FROM Products;
National Specialized Institute for Vocational Training MASCARA
DB - S2 SQL (Structured Query Language)

The SQL COUNT()

The COUNT() function returns the number of rows that matches a


specified criterion.
Example: Find the total number of rows in the Products table:
SELECT COUNT(*)
FROM Products;

The SQL SUM() Function


The SUM() function returns the total sum of a numeric column.
Example: Return the sum of all Quantity fields in the Order
Details table:
SELECT SUM(Quantity)
FROM OrderDetails;

The SQL AVG()


The AVG() function returns the average value of a numeric column.
Example: Find the average price of all products:
SELECT AVG(Price)
FROM Products;
National Specialized Institute for Vocational Training MASCARA
DB - S2 SQL (Structured Query Language)

SQL SELECT DISTINCT


The SELECT DISTINCT statement is used to return only distinct
(different) values.
Example: Select all the different countries from the "Customers" table:
SELECT DISTINCT Country
FROM Customers;

You might also like