0% found this document useful (0 votes)
57 views

Count SUM MAX MIN AVG

The document discusses several SQL aggregation functions - COUNT(), SUM(), AVG(), MAX(), MIN() - and how to use them to aggregate and analyze data from tables. It provides examples of using each function in a SELECT statement, optionally combined with other clauses like WHERE, GROUP BY, HAVING and ORDER BY, to count, sum, find the average, maximum or minimum of columns in a table.

Uploaded by

AKASH JAISWAL
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)
57 views

Count SUM MAX MIN AVG

The document discusses several SQL aggregation functions - COUNT(), SUM(), AVG(), MAX(), MIN() - and how to use them to aggregate and analyze data from tables. It provides examples of using each function in a SELECT statement, optionally combined with other clauses like WHERE, GROUP BY, HAVING and ORDER BY, to count, sum, find the average, maximum or minimum of columns in a table.

Uploaded by

AKASH JAISWAL
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

Firefox https://www.codecademy.com/learn/learn-sql/modules/learn-sql-aggregat...


COUNT()

SUM()

MAX()

MIN()

AVG()

COUNT()
COUNT()
SELECT COUNT(*)
FROM employees
WHERE experience < 5;

* COUNT(*)
COUNT(column) NULL

SUM()
SUM()
SELECT SUM(salary)
FROM salary_disbursement;

AVG()
AVG()
SELECT AVG(salary)
salary FROM employees
WHERE experience < 5;

1 of 3 6/22/2020, 7:52 PM
Firefox https://www.codecademy.com/learn/learn-sql/modules/learn-sql-aggregat...

ROUND()
ROUND()
SELECT year,
ROUND(AVG(rating), 2)
FROM movies
WHERE year = 2015;

GROUP BY
GROUP BY
SELECT rating,
COUNT(*)
GROUP BY FROM movies
FROM WHERE GROUP BY rating;

ORDER BY LIMIT

GROUP BY ORDER BY
SELECT COUNT(*) AS 'total_movies',
SELECT rating
FROM movies
GROUP BY 2

GROUP BY 2 rating ORDER BY 1;

ORDER BY 1 total_movies

HAVING
HAVING
SELECT year,
GROUP BY
COUNT(*)
HAVING
FROM movies
GROUP BY year
HAVING COUNT(*) > 5;

MAX()
MAX()
SELECT MAX(amount)
FROM transactions;
amount

2 of 3 6/22/2020, 7:52 PM
Firefox https://www.codecademy.com/learn/learn-sql/modules/learn-sql-aggregat...

MIN()
MIN()
SELECT MIN(amount)
amount FROM transactions;

transactions

3 of 3 6/22/2020, 7:52 PM

You might also like